Bug 245069

Summary: devel/nasm emits wrong ELF brand
Product: Ports & Packages Reporter: unitrunker <unitrunker>
Component: Individual Port(s)Assignee: Niclas Zeising <zeising>
Status: Closed FIXED    
Severity: Affects Some People CC: dim, zeising
Priority: --- Flags: zeising: maintainer-feedback+
zeising: merge-quarterly?
Version: Latest   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Fix nasm's ELF_OSABI field when emitting object files none

Description unitrunker 2020-03-26 11:09:11 UTC
$ nasm -f elf64 hello.asm
$ ld hello.o -o hello
$ ./hello
ELF binary type "0" not known.

This can be fixed with brandelf:

$ brandelf -t freebsd hello

$ ./hello
Hello world!

However, the brandelf step should not be necessary.
Comment 1 unitrunker 2020-03-26 11:10:52 UTC
Additional reference:
https://forums.freebsd.org/threads/tiny-nasm-program-wont-run.74681/
Comment 2 Niclas Zeising freebsd_committer freebsd_triage 2020-03-27 09:19:51 UTC
Do you know when this started?  nasm hasn't had a new release and update in over a year.  I wonder if this is a change in lld, or something else?
Which version of FreeBSD are you using?
Comment 3 Niclas Zeising freebsd_committer freebsd_triage 2020-03-27 09:55:27 UTC
I did a quick check, this looks like an issue with ldd, when I use gnu ld to link the object it works as expected. lld has been made the default ld on 12.1 and 13, so that might be the difference from earlier, when it worked.
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2020-03-27 10:29:05 UTC
Created attachment 212749 [details]
Fix nasm's ELF_OSABI field when emitting object files
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2020-03-27 10:30:55 UTC
(In reply to Dimitry Andric from comment #4)
Note that ideally this would be some sort of command line option, but I think it is too much trouble to bother, unless somebody would want to upstream this (if an upstream even exists? :)
Comment 6 unitrunker 2020-03-27 12:06:16 UTC
This worked fine for me on 11.2-RELEASE. Now on 12.1-RELEASE-p3
Comment 7 unitrunker 2020-03-27 12:09:51 UTC
(In reply to Dimitry Andric from comment #5)
Can ld infer this from the .o file?
Comment 8 Dimitry Andric freebsd_committer freebsd_triage 2020-03-27 12:45:33 UTC
(In reply to unitrunker from comment #7)
Well, it infers that you are attempting to link the wrong type of .o file for the target system. If you want to link a linux .o file, you should use a target of e.g. x86_64-unknown-linux. The default is obviously to link a freebsd executable, and for that you need freebsd-branded object files. It will not attempt to "correct" any badly branded object files.
Comment 9 commit-hook freebsd_committer freebsd_triage 2020-07-20 18:22:12 UTC
A commit references this bug:

Author: zeising
Date: Mon Jul 20 18:22:04 UTC 2020
New revision: 542660
URL: https://svnweb.freebsd.org/changeset/ports/542660

Log:
  devel/nasm: Update to 2.15.03

  Update devel/nasm to 2.15.03
  Add a patch to fix nasm's ELF_OSABI field when emitting object files [1]

  Changelog:
  https://nasm.us/doc/nasmdocc.html

  PR:		245069 [1]
  Submitted by:	dim [1]
  Reported by:	unitrunker gmail com [1]
  MFH:		2020Q3

Changes:
  head/devel/nasm/Makefile
  head/devel/nasm/distinfo
  head/devel/nasm/files/
  head/devel/nasm/files/patch-output_outelf.c
Comment 10 Niclas Zeising freebsd_committer freebsd_triage 2020-07-20 18:26:54 UTC
Committed, together with nasm update.  Awaiting MFC.
Comment 11 commit-hook freebsd_committer freebsd_triage 2020-07-22 16:28:14 UTC
A commit references this bug:

Author: zeising
Date: Wed Jul 22 16:27:33 UTC 2020
New revision: 542873
URL: https://svnweb.freebsd.org/changeset/ports/542873

Log:
  MFH: r542660 r542869

  devel/nasm: Update to 2.15.03

  Update devel/nasm to 2.15.03
  Add a patch to fix nasm's ELF_OSABI field when emitting object files [1]

  Changelog:
  https://nasm.us/doc/nasmdocc.html

  PR:		245069 [1]
  Submitted by:	dim [1]
  Reported by:	unitrunker gmail com [1]

  devel/nasm: Update to 2.15.03

  Update devel/nasm to 2.15.03
  Changelog:
  https://nasm.us/doc/nasmdocc.html

  Approved by:	ports-secteam (joenum)

Changes:
_U  branches/2020Q3/
  branches/2020Q3/devel/nasm/Makefile
  branches/2020Q3/devel/nasm/distinfo
  branches/2020Q3/devel/nasm/files/
Comment 12 Niclas Zeising freebsd_committer freebsd_triage 2020-07-22 16:31:39 UTC
Merged, closing.