Bug 230239

Summary: graphics/mesa-libs: fails to build on i386 with lld as /usr/bin/ld
Product: Ports & Packages Reporter: Ed Maste <emaste>
Component: Individual Port(s)Assignee: freebsd-x11 (Nobody) <x11>
Status: Closed FIXED    
Severity: Affects Only Me Flags: bugzilla: maintainer-feedback? (x11)
Priority: ---    
Version: Latest   
Hardware: i386   
OS: Any   
See Also: https://bugs.freedesktop.org/show_bug.cgi?id=4197
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225741
Bug Depends on:    
Bug Blocks: 214864    

Description Ed Maste freebsd_committer freebsd_triage 2018-07-31 13:07:38 UTC
The migration to the LLVM project's lld linker as the system linker (/usr/bin/ld) for FreeBSD is in progress - it is the case for arm64 and amd64 today, and i386 will switch once ports issues are addressed - see exp-run in PR214864.

Attempting to link mesa-libs on i386 with lld fails with:

/usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: _glapi_Dispatch in readonly segment; recompile object files with -fPIC
>>> defined in .libs/shared_glapi_libglapi_la-u_current.o
>>> referenced by entry.c
>>>               .libs/shared_glapi_libglapi_la-entry.o:(.text+0x1)

/usr/bin/ld: error: can't create dynamic relocation R_386_PC32 against symbol: _glapi_get_dispatch in readonly segment; recompile object files with -fPIC
>>> defined in .libs/shared_glapi_libglapi_la-u_current.o
>>> referenced by entry.c
>>>               .libs/shared_glapi_libglapi_la-entry.o:(.text+0xC)

/usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: _glapi_Dispatch in readonly segment; recompile object files with -fPIC
>>> defined in .libs/shared_glapi_libglapi_la-u_current.o
>>> referenced by entry.c
>>>               .libs/shared_glapi_libglapi_la-entry.o:(.text+0x21)

...

http://package18.nyi.freebsd.org/data/headi386PR214864-default/2018-07-30_18h09m59s/logs/errors/mesa-libs-18.1.4.log
Comment 1 Ed Maste freebsd_committer freebsd_triage 2018-07-31 13:48:09 UTC
Useful links:
https://dri.freedesktop.org/wiki/GLdispatch
https://bugs.freedesktop.org/show_bug.cgi?id=4197

Have been discussing on IRC w/ zeising@, it appears this comes from non-PIC asm (presumably inline asm via a header). Probably most suitable approach is to add -znotext to LDFLAGS on i386.
Comment 2 Ed Maste freebsd_committer freebsd_triage 2018-08-01 12:31:43 UTC
Same issue was fixed in openjdk in PR225741 although it had an additional complication because the openjdk build does not honour LDFLAGS.

Here I think that this should work:

.if ${ARCH} == i386
# PR230239 Fix the build for i386 when WITH_LLD_IS_LD is set
LDFLAGS+=-Wl,-z,notext
.endif
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-08-01 18:31:32 UTC
A commit references this bug:

Author: zeising
Date: Wed Aug  1 18:30:52 UTC 2018
New revision: 476189
URL: https://svnweb.freebsd.org/changeset/ports/476189

Log:
  Fix build with lld linker on i386

  Fix the build with the lld linker on i386.  This is done by adding an option
  to the linker to allow relocations in read-only segments, since there are
  some assembler code that's not PIC.
  the gnu ld linker does this by default.

  PR:		230239
  Submitted by:	emaste

Changes:
  head/graphics/mesa-libs/Makefile