Bug 223680 - www/firefox: DTRACE=on fails with /usr/bin/ld: error: ../../js/src/jsarray.o: string table non-null terminated
Summary: www/firefox: DTRACE=on fails with /usr/bin/ld: error: ../../js/src/jsarray.o:...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks: 214864
  Show dependency treegraph
 
Reported: 2017-11-15 11:53 UTC by Jan Beich
Modified: 2017-11-16 23:04 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2017-11-15 11:53:24 UTC
I'd like to use lld in order to fix bug 222641. jsarray.o links fine until processed by dtrace -G. bfd and gold are unaffected. Any clue why?

$ c++ -v
FreeBSD clang version 5.0.0 (tags/RELEASE_500/final 312559) (based on LLVM 5.0.0svn)
Target: x86_64-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin

$ ln -fs ld.lld /usr/bin/ld
$ c++ -Wl,-V
LLD 5.0.0 (FreeBSD 312559) (compatible with GNU linkers)

$ sed -i '.bak' '/LLD_UNSAFE/d' /usr/ports/Mk/bsd.gecko.mk
$ cd /usr/ports/www/firefox
$ make
[...]
/usr/bin/ld: error: ../../js/src/jsarray.o: string table non-null terminated
c++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 1 Jan Beich freebsd_committer freebsd_triage 2017-11-15 12:00:54 UTC
Over to toolchain@ to investigate as gecko@ already defines LLD_UNSAFE as a workaround.
Comment 2 Jan Beich freebsd_committer freebsd_triage 2017-11-15 12:20:53 UTC
Another way to reproduce:

$ ln -fs ld.lld /usr/bin/ld
$ pkg install autoconf213 gmake python27 mercurial
$ hg clone https://hg.mozilla.org/mozilla-central
$ cd mozilla-central/js/src
$ autoconf-2.13
$ ./configure --disable-jemalloc --enable-dtrace
$ gmake
[...]
/usr/bin/ld: error: ../jsarray.o: string table non-null terminated
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2017-11-15 21:07:06 UTC
After dtrace processes the jsarray.o file, its .strtab session is no longer null-terminated, e.g. before dtrace it looks like:

Hex dump of section '.strtab':
  0x00000000 005f5a32 354a535f 5265706f 72744572 ._Z25JS_ReportEr
  0x00000010 726f724e 756d6265 72415343 49495039 rorNumberASCIIP9
  0x00000020 4a53436f 6e746578 74504650 4b31394a JSContextPFPK19J
  0x00000030 53457272 6f72466f 726d6174 53747269 SErrorFormatStri
  0x00000040 6e675076 6a455334 5f6a7a00 6d656d63 ngPvjES4_jz.memc
  0x00000050 7079002e 72656c61 2e746578 742e5f5a py..rela.text._Z
  0x00000060 4c323043 72656174 65417272 61795072 L20CreateArrayPr
  0x00000070 6f746f74 79706550 394a5343 6f6e7465 ototypeP9JSConte
...
  0x00006ea0 5f30002e 4c435049 34345f30 002e4c43 _0..LCPI44_0..LC
  0x00006eb0 50493234 5f30002e 4c435049 33335f30 PI24_0..LCPI33_0
  0x00006ec0 002e4c43 50493233 5f30002e 4c435049 ..LCPI23_0..LCPI
  0x00006ed0 325f3000 2e4c4350 4933315f 30002e4c 2_0..LCPI31_0..L
  0x00006ee0 43504932 315f3000 2e4c4350 4933305f CPI21_0..LCPI30_
  0x00006ef0 30002e4c 43504932 305f3000 2e4c2e73 0..LCPI20_0..L.s
  0x00006f00 74722e39 30002e72 6f646174 612e5f5a tr.90..rodata._Z
  0x00006f10 4c313070 6f776572 734f6631 30002e4c L10powersOf10..L
  0x00006f20 2e737472 2e313000                   .str.10.

After dtrace:

Hex dump of section '.strtab':
  0x00000000 005f5a32 354a535f 5265706f 72744572 ._Z25JS_ReportEr
  0x00000010 726f724e 756d6265 72415343 49495039 rorNumberASCIIP9
  0x00000020 4a53436f 6e746578 74504650 4b31394a JSContextPFPK19J
  0x00000030 53457272 6f72466f 726d6174 53747269 SErrorFormatStri
  0x00000040 6e675076 6a455334 5f6a7a00 6d656d63 ngPvjES4_jz.memc
  0x00000050 7079002e 72656c61 2e746578 742e5f5a py..rela.text._Z
  0x00000060 4c323043 72656174 65417272 61795072 L20CreateArrayPr
  0x00000070 6f746f74 79706550 394a5343 6f6e7465 ototypeP9JSConte
...
  0x000073a0 52657573 6547726f 75704550 394a5343 ReuseGroupEP9JSC
  0x000073b0 6f6e7465 78744e32 4a533648 616e646c ontextN2JS6Handl
  0x000073c0 65495038 4a534f62 6a656374 45456d00 eIP8JSObjectEEm.
  0x000073d0 24647472 6163652e 5f5a4e32 6a733134 $dtrace._ZN2js14
  0x000073e0 4e65774f 626a6563 74436163 68653136 NewObjectCache16
  0x000073f0 6e65774f 626a6563 7446726f 6d486974 newObjectFromHit
  0x00007400 4550394a 53436f6e 74657874 694e535f EP9JSContextiNS_
  0x00007410 32676331 31496e69 7469616c 48656170 2gc11InitialHeap
  0x00007420 4500a5a5 a5a5a5a5 a5                E........

It looks like dtrace appends some uninitialized memory at the end of the table.  I have not been able to successfully run valgrind on it, though, so I have no idea where it comes from.
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2017-11-16 06:41:17 UTC
This is a problem with r313504. It occurs when linking with ld.bfd as well, it's just that lld is more strict.
Comment 5 commit-hook freebsd_committer freebsd_triage 2017-11-16 07:14:52 UTC
A commit references this bug:

Author: markj
Date: Thu Nov 16 07:14:29 UTC 2017
New revision: 325886
URL: https://svnweb.freebsd.org/changeset/base/325886

Log:
  Take r313504 into account when recomputing the string table length.

  When we encounter a USDT probe in a weak symbol, we emit an alias for
  the probe function symbol. Such aliases are named differently from the
  aliases we emit for probes in local functions, so make sure to take that
  difference into account when resizing the output object file's string
  table. Otherwise, we underrun the string table buffer.

  PR:		223680

Changes:
  head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_link.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2017-11-16 23:04:35 UTC
A commit references this bug:

Author: jbeich
Date: Thu Nov 16 23:04:25 UTC 2017
New revision: 454358
URL: https://svnweb.freebsd.org/changeset/ports/454358

Log:
  gecko: allow lld as ld on FreeBSD 12.0

  PR:		223680

Changes:
  head/Mk/bsd.gecko.mk