Bug 23746 - Debugging under x86_64-apple-darwin18.0.0 getting "not in executable format"
Summary: Debugging under x86_64-apple-darwin18.0.0 getting "not in executable format"
Status: RESOLVED DUPLICATE of bug 23728
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2018-10-08 13:58 UTC by romain margheriti
Modified: 2018-12-10 17:26 UTC (History)
5 users (show)

See Also:
Last reconfirmed: 2018-11-06 00:00:00

Hello world executable (740 bytes, application/octet-stream)
2018-10-08 20:21 UTC, romain margheriti

Note You need to log in before you can comment on or make changes to this bug.
Description romain margheriti 2018-10-08 13:58:42 UTC
Since I've installed Xcode 10 I'm not able to use GDB anymore.

Here some information about my system :

MacOs Mojave 10.14

$ clang -v
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ file a.out
a.out: Mach-O 64-bit executable x86_64

$ gdb show configuration
(gdb) This GDB was configured as follows:
   configure --host=x86_64-apple-darwin18.0.0 --target=x86_64-apple-darwin18.0.0
             --with-gdb-datadir=/usr/local/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/local/lib/gdb (relocatable)

$ gdb a.out
Type "apropos word" to search for commands related to "word"...
BFD: /Users/romain/a.out: unknown load command 0x32
BFD: /Users/romain/a.out: unknown load command 0x32
"/Users/romain/a.out": not in executable format: file format not recognized

I've tried to install gdb in different ways, using homebrew, from sources, and from HEAD but still getting stuck.

From Head I get this message during make install:

"ranlib: /usr/local/lib/libbfd.a(archive.o): unknown load command 0x32" for all libs.

Feel free to ask if you need more information about my configuration.
Comment 1 Tom Tromey 2018-10-08 17:42:35 UTC
Refiling to binutils since I think BFD issues are usually handled there.

Offhand it seems like there must be some mach-o change in Mojave
and BFD hasn't yet been updated to account for this.  I wouldn't be
surprised if, once this is fixed, there's also some gdb change
needed as well.
Comment 2 Tom Tromey 2018-10-08 17:43:25 UTC
I don't have Mojave yet, maybe others don't either -- one thing that
might help is attaching a "hello-world" (i.e., tiny) executable
showing the problem.
Comment 3 romain margheriti 2018-10-08 20:21:22 UTC
Created attachment 11297 [details]
Hello world executable
Comment 4 romain margheriti 2018-10-25 18:21:18 UTC
So, I found a solution.

The trouble is that clang-1000.11.45.2 brings a new command `LC_BUILD_VERSION` inside o-mach file that isn't wet interpreted by bfd.

I esealy fixed this issue adding `BFD_MACH_O_LC_BUILD_VERSION = 0x32` to `include/mach-o/loader.h` line 189 and `case BFD_MACH_O_LC_BUILD_VERSION:break;` to `bfd/mach-o.c` line 4649.
Comment 5 Tom Tromey 2018-10-25 18:28:23 UTC
Thanks for the investigation, this was very helpful!

This looks informative:
Comment 6 Roman Bolshakov 2018-11-05 21:04:00 UTC
This is a duplicate of #23742.
Comment 7 Nick Clifton 2018-11-06 17:19:11 UTC
Hi Tom, Romain,

I have checked in Romain's patch.  Please could one of you confirm that it has worked ?

Comment 8 Francois-Xavier Coudert 2018-11-07 14:07:31 UTC
I can confirm that the latest trunk/master does not exhibit this bug anymore.

Probably Roman's patch at https://sourceware.org/ml/binutils/2018-11/msg00031.html is more extensive, and add support for other macOS features.
Comment 9 Jeffrey Walton 2018-12-03 06:47:56 UTC
Probably a duplicate of https://sourceware.org/bugzilla/show_bug.cgi?id=23728
Comment 10 Tom Tromey 2018-12-10 17:26:10 UTC

*** This bug has been marked as a duplicate of bug 23728 ***