Homebrew-core: gnm (binutils) fails on Mojave (and breaks gcc-8)

Created on 28 Sep 2018  路  11Comments  路  Source: Homebrew/homebrew-core

When the binutils formula is not installed, gcc-8 works just fine

KA15-002: gilles$ cat conftest.c 
int main(int argc, char *argv[]) {
    return 0;
}
KA15-002:ompi-master-gcc8 gilles$ gcc-8 conftest.c 
KA15-002:ompi-master-gcc8 gilles$ gnm a.out 
-bash: gnm: command not found

now, after installing binutils, the same command fails

KA15-002: gilles$ brew install binutils
==> Downloading https://homebrew.bintray.com/bottles/binutils-2.31.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring binutils-2.31.1.mojave.bottle.tar.gz
馃嵑  /usr/local/Cellar/binutils/2.31.1: 114 files, 170.8MB
KA15-002: gilles$ gcc-8 conftest.c 
collect2: fatal error: /usr/local/bin/gnm returned 1 exit status
compilation terminated

Here is the error generated by manually invoking gnm

KA15-002: gilles$ /usr/local/bin/gnm a.out 
/usr/local/bin/gnm: a.out: unknown load command 0x32
/usr/local/bin/gnm: a.out: unknown load command 0x32
/usr/local/bin/gnm: a.out: unknown load command 0x32
/usr/local/bin/gnm: a.out: file format not recognized

Unsurprisingly, removing the binutils formula solves the issue.

KA15-002: gilles$ brew uninstall binutils
Uninstalling /usr/local/Cellar/binutils/2.31.1... (114 files, 170.8MB)
KA15-002:ompi-master-gcc8 gilles$ gcc-8 conftest.c 

I initially thought something was wrong with my system (I recently upgraded OS X from High Sierra to Mojave) so uninstalled brew and made a fresh install with just a few packages, and am still able to reproduce the very same issue.

10.14 outdated upstream issue xcode10

Most helpful comment

Hi @ggouaillardet, I have the same problem with Xcode 10, the latest version. (I don't think it is caused by the new OS Mojave because gcc works nicely with old Xcode 7 on Mojave.)

A temporary solution is to set nm to gnm as follows

mv /usr/local/bin/gnm /usr/local/bin/gnm-backup
ln -s /usr/bin/nm /usr/local/bin/gnm

All 11 comments

Indeed, it appears that binutils' gnm cannot read MachO files:

bli /tmp $ cat a.c
int main (void) { return 0; }
bli /tmp $ clang -c a.c 
bli /tmp $ file a.o    
a.o: Mach-O 64-bit object x86_64
bli /tmp $ gnm a.o
gnm: a.o: unknown load command 0x32
gnm: a.o: unknown load command 0x32
gnm: a.o: unknown load command 0x32
gnm: a.o: file format not recognized
bli /tmp $ gnm --version
GNU nm (GNU Binutils) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

Could you report this bug to the binutils project? It does not appear to be specific to Homebrew.

done

the bug report is available at https://sourceware.org/bugzilla/show_bug.cgi?id=23728

Meanwhile, should something been done for Mojave (such as __not__ installing /usr/local/bin/gnm) in order not to break gcc-8 ?

there is even a better idea. stop using that shit from apple

stop using their hardware and software
you can install linux (even windows) on their actual pc(s) and go from there
this battle is endless, they will do whatever it takes to stop you from using real development tools
they will do that till they run belly up, which will happen faster than you/they think

@dmarinescu your trolling is very unwelcome here, good speed.

Hi @ggouaillardet, I have the same problem with Xcode 10, the latest version. (I don't think it is caused by the new OS Mojave because gcc works nicely with old Xcode 7 on Mojave.)

A temporary solution is to set nm to gnm as follows

mv /usr/local/bin/gnm /usr/local/bin/gnm-backup
ln -s /usr/bin/nm /usr/local/bin/gnm

We could introduce a conflict between the two packages, but in general that's not true. It's a case of bug in binutils, so I would suggest to simply uninstall the binutils until it is fixed in a new version.

@fxcoudert I was something in between. For example, we could install nm in /usr/local/bin/gnm-binutils on Mojave/XCode 10

The benefits (to be tested) are :

  • gcc-8 works out of the box regardless binutils is installed or not
  • some other utils provided by binutils that might not be broken are available

I'm going to open a PR to make binutils keg_only since it's so incredibly broken/janky on macOS.

Patch series to address the issue has been sent upstream: https://sourceware.org/ml/binutils/2018-11/msg00031.html

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BluePawDev picture BluePawDev  路  3Comments

daviderestivo picture daviderestivo  路  4Comments

jyutzler picture jyutzler  路  4Comments

yuna9 picture yuna9  路  4Comments

ghostbar picture ghostbar  路  4Comments