Bug 267854 - [exp-run] with llvm-objdump installed as /usr/bin/objdump
Summary: [exp-run] with llvm-objdump installed as /usr/bin/objdump
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Package Infrastructure (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Port Management Team
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-18 20:50 UTC by Ed Maste
Modified: 2023-04-05 01:34 UTC (History)
3 users (show)

See Also:


Attachments
Install llvm-objdump as /usr/bin/objdump (1.28 KB, patch)
2022-11-18 20:50 UTC, Ed Maste
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2022-11-18 20:50:48 UTC
Created attachment 238165 [details]
Install llvm-objdump as /usr/bin/objdump

https://reviews.freebsd.org/D37445
Comment 2 Ed Maste freebsd_committer freebsd_triage 2022-11-25 15:34:55 UTC
misc/seabios is definitely due to different formatting from GNU objdump and llvm-objdump.

Error is:

Traceback (most recent call last):
  File "/wrkdirs/usr/ports/misc/seabios/work/seabios-1.14.0/./scripts/layoutrom.py", line 705, in <module>
    main()
  File "/wrkdirs/usr/ports/misc/seabios/work/seabios-1.14.0/./scripts/layoutrom.py", line 647, in main
    info16 = parseObjDump(infile16, '16')
  File "/wrkdirs/usr/ports/misc/seabios/work/seabios-1.14.0/./scripts/layoutrom.py", line 562, in parseObjDump
    relocsection = sectionmap[sectionname]
KeyError: '.text.call32_prep'


GNU objdump produces:

work/seabios-1.14.0/out/code16.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.set_a20 00000020  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .text.set_code_success 0000000c  00000000  00000000  00000054  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  3 .text.pic_eoi2 00000008  00000000  00000000  00000060  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .text.call32_prep 00000099  00000000  00000000  00000068  2**0
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
...


while llvm-objdump produces:


out/code16.o:   file format elf32-i386

Sections:
Idx Name                                      Size     VMA      Type
  0                                           00000000 00000000
  1 .text                                     00000000 00000000 TEXT
  2 .text.set_a20                             00000020 00000000 TEXT
  3 .text.set_code_success                    0000000c 00000000 TEXT
  4 .text.pic_eoi2                            00000008 00000000 TEXT
  5 .text.call32_prep                         00000099 00000000 TEXT
...

(llvm-objdump also reports a greater number of sections in the list, but it may be that code16.o in the work dir had been processed at the time I ran GNU objdump) 

seabios has `USE_BINUTILS=   yes`, but it is picking up llvm objdump in $PATH.  Its Makefile has:

CROSS_PREFIX=
ifneq ($(CROSS_PREFIX),)
CC=$(CROSS_PREFIX)gcc
endif
AS=$(CROSS_PREFIX)as
LD=$(CROSS_PREFIX)ld
OBJCOPY=$(CROSS_PREFIX)objcopy
OBJDUMP=$(CROSS_PREFIX)objdump
STRIP=$(CROSS_PREFIX)strip
PYTHON=python
CPP=cpp


so it looks like seabios should be modified so that it actually picks up GNU objdump, but we should also get llvm-objdump's formatting fixed.

============================================================


math/reduce looks like it might have been OOM and not due to the objdump change:

Info: [Bootstrap] reset
Info: [Bootstrap] cali
gmake[3]: *** [Makefile:6885: bootstrapreduce.img] Killed


============================================================


games/pioneer also looks like it might not be related to objdump change:

Compressed model (bowfin): 1188.47 KB -> 640.09 KB
Compiling "bowfin" took: 256.523954
---
Starting compiler for (deneb)
Segmentation fault
ninja: build stopped: subcommand failed.
*** Error code 1

(It may be a second order effect where we've built a broken build tool though.)
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2022-11-25 20:02:41 UTC
(In reply to Ed Maste from comment #2)
Looks like GNU objdump's output is without the -W (--wide) option? I think if you use that, the format will look similar to llvm-objdump's.
Comment 4 Ed Maste freebsd_committer freebsd_triage 2022-11-25 20:16:25 UTC
(In reply to Dimitry Andric from comment #3)

Yeah, it looks like --wide produces output similar to llvm-objdump, but with additional fields. However seabios is expecting GNU without --wide format. Idx is also off by one for GNU vs llvm.

% /usr/local/bin/objdump --wide -h code16.o | head

code16.o:     file format elf32-i386

Sections:
Idx Name                                     Size      VMA       LMA       File off  Algn  Flags
  0 .text                                    00000000  00000000  00000000  00000034  2**0  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.set_a20                            00000020  00000000  00000000  00000034  2**0  CONTENTS, ALLOC, LOAD, READONLY, CODE

% /usr/local/bin/objdump -h code16.o | head

code16.o:     file format elf32-i386

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text.set_a20 00000020  00000000  00000000  00000034  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

% ~/src/llvm-project/build/bin/llvm-objdump -h code16.o | head

code16.o:       file format elf32-i386

Sections:
Idx Name                                      Size     VMA      Type
  0                                           00000000 00000000 
  1 .text                                     00000000 00000000 TEXT
  2 .text.set_a20                             00000020 00000000 TEXT
Comment 5 Ed Maste freebsd_committer freebsd_triage 2022-11-26 03:31:35 UTC
A patch to make seabios use readelf/llvm-readelf instead: https://github.com/MaskRay/seabios/commit/39ee69b81361f75afcac1dcf5b41ba475890c5de

This looks like the proper fix
Comment 6 Roger Pau Monné freebsd_committer freebsd_triage 2022-11-28 10:13:52 UTC
(In reply to Ed Maste from comment #5)
Do you know if that's submitted upstream?

Last time I checked SeaBIOS explicitly required gcc and binutils to build, but now it's possible to build with clang/llvm?

Thanks for looking into this!
Comment 7 Ed Maste freebsd_committer freebsd_triage 2022-11-28 16:13:03 UTC
(In reply to Roger Pau Monné from comment #6)
MaskRay submitted a series of patches to build seabios with lld and avoid requiring GNU objdump, mentioned in my now-closed GitHub issue about formatting differences between GNU objdump and LLVM.

https://github.com/llvm/llvm-project/issues/59204
https://github.com/MaskRay/seabios/tree/readelf
https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/KBHQU4OLW2THG5Q5F5X7EWTQDJHKNVYC/

(Mailing list archive link is currently reporting "Server error" for me)

I suspect the best path is to patch locally to honour OBJDUMP (and other tools) set in environment to unblock this issue. Also submit upstream, as it seems like a good idea (regardless of whether we use objdump or readelf).

Separately ping MaskRay's thread to see if we can get that committed.
Comment 8 commit-hook freebsd_committer freebsd_triage 2022-12-12 13:37:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=766fafa0aaaebdaadb520fdc90d2d86d6f0cf471

commit 766fafa0aaaebdaadb520fdc90d2d86d6f0cf471
Author:     Joseph Mingrone <jrm@FreeBSD.org>
AuthorDate: 2022-12-09 22:08:41 +0000
Commit:     Joseph Mingrone <jrm@FreeBSD.org>
CommitDate: 2022-12-12 13:36:30 +0000

    misc/seabios: Update to 1.16.0; use binutils binaries

    Upstream release information:
    https://www.seabios.org/Releases#SeaBIOS_1.15.0
    https://www.seabios.org/Releases#SeaBIOS_1.16.0

    When ports set USE_BINUTILS=yes, the environment is adjusted with, e.g.,
    OBJDUMP=${LOCALBASE}/bin/objdump, so that binaries from devel/binutils
    are used during the build.  SeaBIOS, however, ignores these environment
    variables, so supply them to MAKE_ARGS.  This will fix the build when
    /usr/bin/llvm-objdump is linked to /usr/bin/objdump.  See PR 267854.

    PR:             267854
    Approved by:    royger (maintainer)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D37667

 misc/seabios/Makefile | 5 +++--
 misc/seabios/distinfo | 6 +++---
 2 files changed, 6 insertions(+), 5 deletions(-)
Comment 9 Ed Maste freebsd_committer freebsd_triage 2022-12-12 15:25:43 UTC
(In reply to Ed Maste from comment #2)
I extracted games/pioneer and "objdump" does not appear in the tree. I assume that it and math/reduce are unrelated failures.
Comment 10 commit-hook freebsd_committer freebsd_triage 2022-12-12 15:36:41 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=86edb11e7491e657e6c75ef6814867021665c377

commit 86edb11e7491e657e6c75ef6814867021665c377
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-11-18 20:47:13 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-12-12 15:36:02 +0000

    Always install llvm-objdump as objdump

    Instead of providing no /usr/bin/objdump when LLVM_BINUTILS is false.

    PR:             267854 [exp-run]
    Reviewed by:    dim
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D37445

 UPDATING                                 | 8 ++++++++
 tools/build/mk/OptionalObsoleteFiles.inc | 7 ++-----
 usr.bin/clang/llvm-objdump/Makefile      | 2 --
 3 files changed, 10 insertions(+), 7 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2023-04-05 01:34:41 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=982e61aacc79f5b972e4c6e1dab6221403e58b0a

commit 982e61aacc79f5b972e4c6e1dab6221403e58b0a
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-11-18 20:47:13 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-04-05 01:33:57 +0000

    Always install llvm-objdump as objdump

    Instead of providing no /usr/bin/objdump when LLVM_BINUTILS is false.

    PR:             267854 [exp-run]
    Reviewed by:    dim
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D37445

    (cherry picked from commit 86edb11e7491e657e6c75ef6814867021665c377)

 UPDATING                                 | 8 ++++++++
 tools/build/mk/OptionalObsoleteFiles.inc | 7 ++-----
 usr.bin/clang/llvm-objdump/Makefile      | 2 --
 3 files changed, 10 insertions(+), 7 deletions(-)