Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression in 2020.11.02.00] can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC #399

Closed
yurivict opened this issue Nov 3, 2020 · 10 comments

Comments

@yurivict
Copy link

yurivict commented Nov 3, 2020

d: error: can't create dynamic relocation R_X86_64_64 against local symbol in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in thrift/compiler/generate/CMakeFiles/compiler_generate_templates.dir/templates.cc.o
>>> referenced by templates.cc
>>>               thrift/compiler/generate/CMakeFiles/compiler_generate_templates.dir/templates.cc.o:(apache::thrift::compiler::templates_name_datas)

FreeBSD 12.2

@Boarders
Copy link

I am running into this issue trying to build fbthrift, any ideas on what to do to solve it?

@yurivict
Copy link
Author

The error message itself says what to do.

@vitaut
Copy link
Contributor

vitaut commented Jan 22, 2024

Can be done by setting the CMAKE_POSITION_INDEPENDENT_CODE CMake variable. Closing as this is more of a configuration than Thrift issue.

@vitaut vitaut closed this as completed Jan 22, 2024
@yurivict
Copy link
Author

No, this is a bug in thrift because it fails without special setting by the user.
Thrift requires PIC to build and fails to set the PIC flag.

@vitaut
Copy link
Contributor

vitaut commented Jan 23, 2024

How do you build thrift? Could you provide repro command(s)?

@yurivict
Copy link
Author

We build with cmake <args> . && make, but we use -DBUILD_SHARED_LIBS=YES in args.

When -DBUILD_SHARED_LIBS=YES is added the build should add -fPIC to build successfully.

@vitaut
Copy link
Contributor

vitaut commented Jan 23, 2024

If you enable shared libraries then you should also enable PIC, the normal build configuration doesn't require any of that. That said, a PR to enable PIC if BUILD_SHARED_LIBS is set would be welcome.

@yurivict
Copy link
Author

@vitaut

If you enable shared libraries then you should also enable PIC [...]

FYI: This isn't how cmake projects normally work. Setting BUILD_SHARED_LIBS=ON should automatically set -fPIC through cmake. This happens for virtually all projects. There's either a bug in the fbthrift project, or in cmake that is somehow triggered by fbthrift.

@vitaut
Copy link
Contributor

vitaut commented Jan 23, 2024

Ah, you are right. We should enable POSITION_INDEPENDENT_CODE for some intermediate static libraries that get linked into shared libraries.

@vitaut vitaut reopened this Jan 23, 2024
facebook-github-bot pushed a commit that referenced this issue Jan 24, 2024
Summary:
Compile `compiler_generators` with `-fPIC` when building shared libraries.

#399

https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-cmakelists-txt-position-independent-code

Reviewed By: avalonalex

Differential Revision: D53018308

fbshipit-source-id: f620a25dc72df60dd51f43fd832b455df4fefba4
facebook-github-bot pushed a commit to facebook/hhvm that referenced this issue Jan 24, 2024
Summary:
Compile `compiler_generators` with `-fPIC` when building shared libraries.

facebook/fbthrift#399

https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html#mathfunctions-cmakelists-txt-position-independent-code

Reviewed By: avalonalex

Differential Revision: D53018308

fbshipit-source-id: f620a25dc72df60dd51f43fd832b455df4fefba4
@vitaut
Copy link
Contributor

vitaut commented Jan 24, 2024

This particular error should be fixed in 8a08254.

@vitaut vitaut closed this as completed Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants