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

Always use PIC on FreeBSD, just like on Linux #2938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valpackett
Copy link
Contributor

This fixes errors like

[…]
/usr/bin/ld: error: can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol: _D4core5cpuid6_ssse3yb in reado
nly segment; recompile object files with -fPIC                                                                               
>>> defined in runtime/objects-shared/core/cpuid.o
>>> referenced by cpuid.d                                                                                                    
>>>               runtime/objects-shared/core/cpuid.o:(_D4core5cpuid5ssse3FNaNbNdNiNeZb)                                     

/usr/bin/ld: error: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol: _D4core5cpuid6_ssse3yb in read
only segment; recompile object files with -fPIC
>>> defined in runtime/objects-shared/core/cpuid.o
>>> referenced by cpuid.d
>>>               runtime/objects-shared/core/cpuid.o:(_D4core5cpuid5ssse3FNaNbNdNiNeZb)                                     
                                                                                                                             
/usr/bin/ld: error: can't create dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol: _D4core5cpuid6_sse41yb in reado
nly segment; recompile object files with -fPIC                                                                               
>>> defined in runtime/objects-shared/core/cpuid.o                                                                           
>>> referenced by cpuid.d
>>>               runtime/objects-shared/core/cpuid.o:(_D4core5cpuid5sse41FNaNbNdNiNeZb)                                     

/usr/bin/ld: error: can't create dynamic relocation R_AARCH64_LDST8_ABS_LO12_NC against symbol: _D4core5cpuid6_sse41yb in read
only segment; recompile object files with -fPIC
>>> defined in runtime/objects-shared/core/cpuid.o
>>> referenced by cpuid.d
>>>               runtime/objects-shared/core/cpuid.o:(_D4core5cpuid5sse41FNaNbNdNiNeZb)

and allows ASLR on HardenedBSD (/ "coming soon" ASR on upstream FreeBSD) to do its thing

This fixes errors like 'can't create dynamic relocation R_AARCH64_...'
@kinke
Copy link
Member

kinke commented Dec 13, 2018

This shouldn't happen when linking shared druntime. The D modules for shared libraries are/should be explicitly compiled with -relocation-model=pic: https://github.com/ldc-developers/ldc/blob/master/runtime/CMakeLists.txt#L596

@valpackett
Copy link
Contributor Author

This was coming from the variants macro I think. (But adding -relocation-model=pic there resulted in complaining about this option used two times.)

@kinke
Copy link
Member

kinke commented Dec 13, 2018

But adding -relocation-model=pic there resulted in complaining about this option used two times

Used two times because it's added in build_runtime_variant() I referred to; the variants macro calls the former. That's why I'm saying you shouldn't have troubles when linking shared druntime with current master.

@valpackett
Copy link
Contributor Author

hm. I actually ended up with these after screwing with the CMake files. The original errors are in curl

/usr/bin/ld: error: can't create dynamic relocation R_AARCH64_ADD_ABS_LO12_NC against symbol: _D6object__T7destroyTS3std3net4curl4SMTP4ImplZQBiFKQBeZ9__lambda3MFNaNbNiNeZv in readonly segment; recompile object files with -fPIC                         
>>> defined in runtime/objects-debug/etc/c/curl.o
>>> referenced by object.d:530 (/home/greg/src/github.com/ldc-developers/ldc/runtime/druntime/src/object.d:530)              
>>>               runtime/objects-debug/etc/c/curl.o:(_D6object__T7destroyTS3std3net4curl4SMTP4ImplZQBiFKQBeZv)

@kinke
Copy link
Member

kinke commented Dec 14, 2018

This is Phobos now, which should be compiled once as PIC too [without BUILD_SHARED_LIBS=OFF; added in build_runtime_variant() too]. What's the library failing to link?

@kinke
Copy link
Member

kinke commented Dec 14, 2018

Argh... list(APPEND ${phobos2_d_flags} ...) in line 566 should most likely be list(APPEND phobos2_d_flags ...).

@valpackett
Copy link
Contributor Author

Yep looks like that helped

@kinke
Copy link
Member

kinke commented Dec 14, 2018

Thx for checking. So is defaulting to PIC for FreeBSD safe/needed already, or would that fix suffice for the moment?

@valpackett
Copy link
Contributor Author

Not strictly needed all the time I guess, but many C/C++ programs need it for various reasons.

/usr/ports % rg "fPIC" | wc -l
917
/usr/ports % rg "CFLAGS.*fPIC" | wc -l
482

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

Successfully merging this pull request may close these issues.

None yet

2 participants