Bug 225741 - java/openjdk7 java/openjdk8: Fix i386 build when base ld is lld
Summary: java/openjdk7 java/openjdk8: Fix i386 build when base ld is lld
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Greg Lewis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-07 20:23 UTC by Dimitry Andric
Modified: 2018-08-01 12:31 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (glewis)


Attachments
Add -Wl,-z,notext to openjdk[78] link flags (944 bytes, patch)
2018-02-07 20:23 UTC, Dimitry Andric
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2018-02-07 20:23:09 UTC
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.)
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2018-02-07 20:24:43 UTC
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.
Comment 2 Ed Maste freebsd_committer freebsd_triage 2018-02-07 21:21:13 UTC
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.
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2018-02-07 21:52:05 UTC
(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...
Comment 4 Greg Lewis freebsd_committer freebsd_triage 2018-02-08 06:29:36 UTC
I've committed a change for this.  I did limit it to i386.

Thanks!
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-02-08 06:29:53 UTC
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