Created attachment 190400 [details] Add -Wl,-z,notext to openjdk[78] link flags When building either opendjk7 or openjdk8 on i386, with /usr/bin/ld pointing to lld (e.g. using the WITH_LLD_IS_LD option), it dies with many errors of the form: [...] Linking vm... /usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: .L.str in readonly segment; recompile object files with -fPIC >>> defined in adaptiveFreeList.o >>> referenced by adaptiveFreeList.cpp >>> adaptiveFreeList.o:(AdaptiveFreeList<FreeChunk>::print_on(outputStream*, char const*) const) /usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: .L.str.1 in readonly segment; recompile object files with -fPIC >>> defined in adaptiveFreeList.o >>> referenced by adaptiveFreeList.cpp >>> adaptiveFreeList.o:(AdaptiveFreeList<FreeChunk>::print_on(outputStream*, char const*) const) What is happening here is that lld has the "-z text" option on by default (which produces errors when binaries have dynamic relocations in read-only sections), as opposed to BFD ld. For some reason, the openjdk build process does not look at, or care about, the value of LDFLAGS, but uses its own variable LFLAGS for this purpose. This patch adds LFLAGS="-Wl,-z,notext" to MAKE_ENV for both openjdk7 and openjdk8, which turns off the checks for dynamic relocations, and makes the ports build with lld on i386. (A future task could attempt to investigate why these text relocations exist at all, possibly due to some files not being correctly compiled with -fPIC, but this is much more intrusive.)
Note that I have verified this on 12-CURRENT as of 2018-02-07, but it will probably work similarly for 11-STABLE with lld-as-ld.
Perhaps we should set it only for i386 builds? I believe that with lld -z notext may change the generated output, not just allow text relocations.
(In reply to Ed Maste from comment #2) > Perhaps we should set it only for i386 builds? > > I believe that with lld -z notext may change the generated output, not just > allow text relocations. Sure, if that is the case, that is certainly better. I do wonder why amd64 doesn't see those text relocations, though...
I've committed a change for this. I did limit it to i386. Thanks!
A commit references this bug: Author: glewis Date: Thu Feb 8 06:29:03 UTC 2018 New revision: 461197 URL: https://svnweb.freebsd.org/changeset/ports/461197 Log: . Fix the build for i386 when WITH_LLD_IS_LD is set. PR: 225741 Submitted by: dim@ Changes: head/java/openjdk7/Makefile head/java/openjdk8/Makefile