Bug 245069 - devel/nasm emits wrong ELF brand
Summary: devel/nasm emits wrong ELF brand
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Niclas Zeising
Depends on:
Reported: 2020-03-26 11:09 UTC by unitrunker
Modified: 2020-03-27 12:45 UTC (History)
2 users (show)

See Also:
linimon: maintainer-feedback? (zeising)

Fix nasm's ELF_OSABI field when emitting object files (1.09 KB, patch)
2020-03-27 10:29 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 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:
Comment 2 Niclas Zeising freebsd_committer 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 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 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 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 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.