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

Missing -fPIC leads to the build failure: ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC #1706

Open
yurivict opened this issue Oct 24, 2024 · 14 comments

Comments

@yurivict
Copy link

yurivict commented Oct 24, 2024

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '__stack_chk_guard'; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by ceed-identity.c
>>>               build/gallery/identity/ceed-identity.o:(CeedQFunctionInit_Identity)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in build/interface/ceed-basis.o
>>> referenced by ceed-basis.c
>>>               build/interface/ceed-basis.o:(CeedBasisGetCollocatedGrad)

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in build/gallery/ceed-gallery-weak.o
>>> referenced by ceed-gallery-weak.c
>>>               build/gallery/ceed-gallery-weak.o:(.text+0x3E)

FreeBSD 14.1

@jedbrown
Copy link
Member

Could you use make V=1 or make print-CFLAGS and also make print-CC_VENDOR? I suspect we are not correctly identifying vendor for your default C compiler and thus CFLAGS is not getting a suitable default. You can see in the makefile that -fPIC should be added unless STATIC is defined. You can always make CFLAGS='-fPIC -O -march=generic -MMD -MP' manually to supplant the vendor defaults.

@yurivict
Copy link
Author

yurivict commented Oct 24, 2024

With V=1 it prints this:

make: 'lib' with optional backends: 
cc -I./include -DUNDERSCORE -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing   -c -o build/interface/ceed-fortran.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-fortran.c
cc -I./include -DCEED_JIT_SOURCE_ROOT_DEFAULT="\"/usr/local/include/\"" -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing   -c -o build/interface/ceed-jit-source-root-install.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-jit-source-root-install.c
cc -I./include -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing   -c -o build/interface/ceed-jit-tools.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-jit-tools.c
cc -I./include -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing   -c -o build/interface/ceed-operator.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-operator.c
cc -I./include -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing   -c -o build/interface/ceed-preconditioning.o /usr/ports/math/libceed/work/libCEED-0.12.0-763-ge3ae47f6/interface/ceed-preconditioning.c
...
...

@jedbrown
Copy link
Member

Uh, the output you first pasted had the -fPIC, but then you edited to remove it. What is the difference between those two outputs? Please check the other suggestions in my last comment.

@yurivict
Copy link
Author

Uh, the output you first pasted had the -fPIC, but then you edited to remove it. What is the difference between those two outputs? Please check the other suggestions in my last comment.

Sorry, the first one was the patched up version to have -fPIC in the port in order to build it.
The edited version is what is being used by default, wich fails.
Sorry again for the confusion.

@jedbrown
Copy link
Member

I suspect CC_VENDOR is not being detected/supported; please check what is found and see the makefile line to determine what it should be. Also, it would be easier for us if you paste the command you issue rather than only a snippet of the output.

@yurivict
Copy link
Author

The C compiler is conventionally passed to the Makefile as a CC variable.
You should just use $(CC) which in my case evaluates to cc.

@jedbrown
Copy link
Member

Different vendors use different flags, even for "standard" things like -fPIC (which IBM XL compilers insist on calling -qpic). Vendor detection is used to set default flags. You are welcome to provide the correct flags for your system using CFLAGS, or you can check what we determined as your vendor by checking make print-CC_VENDOR and cc --version. It's likely that we just need to map a FreeBSD-specific string to clang or whatever.
https://github.com/CEED/libCEED/blob/main/Makefile#L104-L145

@yurivict
Copy link
Author

make print-CC_VENDOR prints this:

[ variable name]: CC_VENDOR
[        origin]: file
[        flavor]: simple
[         value]: clang
[expanded value]: clang

@jedbrown
Copy link
Member

Is CFLAGS being set by you?

@yurivict
Copy link
Author

Is CFLAGS being set by you?

Yes.

@jedbrown
Copy link
Member

Then you are overriding our CFLAGS detection, in which case, please supply -fPIC when you are building a shared library.

@yurivict
Copy link
Author

The supplied CFLAGS=-O2 -pipe -fstack-protector-strong -fno-strict-aliasing are general CFLAGS. Normally projects should only append to them.

The port does add -fPIC to build successfully.

@jedbrown
Copy link
Member

We wanted libCEED to be usable with unusual toolchains and with more user control, but without needing to edit files. CMake requires platform/toolchain files for this purpose, and both it and autotools run lots of checks at configure time. You could set OPT=$(CFLAGS) and unset CFLAGS if you want the convenience of not specifying -fPIC.

@yurivict
Copy link
Author

Even if you set your own CFLAGS, with the clang compiler they should always contain -fPIC when you are building a shared library.

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

2 participants