Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linuxbrew] gcc-13 doesn't work on an Ubuntu distribution which targets glibc 2.31 #135068

Closed
4 tasks done
CarterLi opened this issue Jun 27, 2023 · 44 comments
Closed
4 tasks done
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age

Comments

@CarterLi
Copy link
Contributor

CarterLi commented Jun 27, 2023

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew config
HOMEBREW_VERSION: 4.0.25
ORIGIN: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
HEAD: 2ccdb26c45e0ac8c7d4a8c2cc78cd577c28a2707
Last commit: 15 hours ago
Core tap JSON: 27 Jun 03:12 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_API_DOMAIN: https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api
HOMEBREW_BOTTLE_DOMAIN: https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
HOMEBREW_BREW_GIT_REMOTE: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
HOMEBREW_DISPLAY: :0
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: quad-core 64-bit unknown_0x7_0x3b
Clang: N/A
Git: 2.41.0 => /home/linuxbrew/.linuxbrew/bin/git
Curl: 7.68.0 => /bin/curl
Kernel: Linux 5.4.18-53-generic x86_64 GNU/Linux
OS: Kylin V10 SP1 (kylin)
Host glibc: 2.31
/usr/bin/gcc: 9.3.0
/usr/bin/ruby: N/A
glibc: N/A
gcc@11: N/A
gcc: N/A
xorg: N/A
$ brew doctor
Your system is ready to brew.

Verification

  • My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

$ touch test.c # make sure that test.c is empty
$ gcc-13 test.c

What happened (include all command output)?

/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so)
collect2: error: ld returned 1 exit status

What did you expect to happen?

Print some link errors like _main is not found

Step-by-step reproduction instructions (by running brew commands)

$ brew install gcc
$ # follow instructions above

Comments

I assume that it was because homebrew binutils is key-only, so that homebrew gcc-13 cound not find /home/linuxbrew/.linuxbrew/bin/ld and failed back to system /usr/bin/ld. However /usr/bin/ld somehow loaded homebrew gcc's lto plugin (may because I was running homebrew gcc), so that everything was massed up.

@CarterLi CarterLi added the bug Reproducible Homebrew/homebrew-core bug label Jun 27, 2023
@CarterLi CarterLi changed the title gcc-13 doesn't work on an Ubuntu distribution which targets glibc 2.31 [linuxbrew] gcc-13 doesn't work on an Ubuntu distribution which targets glibc 2.31 Jun 27, 2023
@carlocab
Copy link
Member

Try doing

brew install glibc

Though, brew should've already done that for you automatically.

@CarterLi
Copy link
Contributor Author

Though, brew should've already done that for you automatically.

Yes. Otherwise gcc itself would not load

@carlocab
Copy link
Member

That's not consistent with your brew config output, though:

glibc: N/A
gcc@11: N/A
gcc: N/A

Could you update the output of brew config and brew doctor after doing brew install gcc?

@CarterLi
Copy link
Contributor Author

CarterLi commented Jun 27, 2023

That's not consistent with your brew config output, though:

glibc: N/A
gcc@11: N/A
gcc: N/A

Could you update the output of brew config and brew doctor after doing brew install gcc?

I got the output when I was submitting the issue.

homebrew glibc was installed, but was not detected by brew doctor. I dont know why

@CarterLi
Copy link
Contributor Author

CarterLi commented Jun 27, 2023

Noting

Git: 2.41.0 => /home/linuxbrew/.linuxbrew/bin/git
Curl: 7.68.0 => /bin/curl

homebrew curl should have been installed as a dependency of homebrew git, but was not detected by brew doctor too

@CarterLi
Copy link
Contributor Author

image

@CarterLi
Copy link
Contributor Author

image

The problem was clear. brew gcc should be able to find brew binutils

@carlocab
Copy link
Member

Try doing

brew link --force binutils

We could probably stop making binutils keg-only on Linux. This was done per the request of the GitHub Actions team, but they no longer put /home/linuxbrew/.linuxbrew/bin in PATH on GHA runners, so it may no longer be needed.


Also:

Please don't use screenshots when sharing the output of commands in your terminal. They're often difficult to read and impossible to reuse (e.g. when looking up error messages). Instead, copy the text here and wrap them in three back-ticks (```) on the line before and on the line after to format them properly.

@CarterLi
Copy link
Contributor Author

Please don't use screenshots when sharing the output of commands in your terminal. They're often difficult to read and impossible to reuse (e.g. when looking up error messages). Instead, copy the text here and wrap them in three back-ticks (```) on the line before and on the line after to format them properly.

I did use three back-ticks, but you didnt trust my post

@osalbahr
Copy link
Sponsor Contributor

Were you able to reproduce this on another Ubuntu system? Idk if it matters but what’s your PATH?

@CarterLi
Copy link
Contributor Author

Were you able to reproduce this on another Ubuntu system?

I don't have other Ubuntu systems

Idk if it matters but what’s your PATH?

/home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games

@osalbahr
Copy link
Sponsor Contributor

What version of Ubuntu are you running? I have access to VM’s of multiple Ubuntu versions:

image

And I doubt it’s related, but Linux 5.4.18 was released in Feb 2020 so I would recommend upgrading and rebooting, sometimes that fixes random things.

@CarterLi
Copy link
Contributor Author

CarterLi commented Jun 30, 2023

It's Ubuntu Kylin, an Chinese redistribution of Ubuntu.

The error was:

error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found

It relates to the version of glibc, but not Ubuntu or kernel or something. It may happen on other systems which use old glibc (older than 2.35)

@osalbahr
Copy link
Sponsor Contributor

Could you paste the output of neofetch? I’m not sure if Kylin comes in versions, but it’s probably tracking the main Ubuntu. It should show in the output.

@CarterLi
Copy link
Contributor Author

CarterLi commented Jun 30, 2023

Let me explain it again:

  1. I installed homebrew gcc-13. binutils-2.40 and glibc-2.35 was installed as dependencies of gcc-13
  2. I confirmed that gcc-13 -c test.c worked fine
  3. But not gcc-13 test.c. It errored with
/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so)
collect2: error: ld returned 1 exit status

Notablely /usr/bin/ld
4. Homebrew gcc-13 incorrectly called the system ld because Homebrew binutils were not in $PATH. However the system ld tries to load LTO plugin of Homebrew gcc for some reason. The LTO plugin of Homebrew gcc targeted GLIBC_2.33 while the system glibc was glibc 2.31, hence the error. The reason why the LTO plugin tried to load the system glibc was unknown.
5. I tried brew link binutils --force. Everything worked fine then.

@CarterLi
Copy link
Contributor Author

CarterLi commented Jun 30, 2023

Could you paste the output of neofetch? I’m not sure if Kylin comes in versions, but it’s probably tracking the main Ubuntu. It should show in the output.

It's Kylin V10 SP1 as printed by brew config. It doesn't track the main Ubuntu version.

@osalbahr
Copy link
Sponsor Contributor

That's not consistent with your brew config output, though:

glibc: N/A
gcc@11: N/A
gcc: N/A

Could you update the output of brew config and brew doctor after doing brew install gcc?

@carlocab FYI, glibc: N/A is consistent with what I get on a homebrew/brew distrobox (a wrapper on podman) but I don't get the error:

linuxbrew@brew:~$ touch test.c 
linuxbrew@brew:~$ gcc-13 test.c
/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../lib/gcc/current/gcc/x86_64-pc-linux-gnu/13/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
linuxbrew@brew:~$ brew config
HOMEBREW_VERSION: 4.0.26
ORIGIN: https://github.com/Homebrew/brew
HEAD: eff45ef570f265e226f14ce91da72d7a6e7d516a
Last commit: 3 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: cf3cb18796664100f963873bfd2d603d80491b74
Core tap last commit: 3 days ago
Core tap branch: master
Core tap JSON: 30 Jun 04:03 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0
HOMEBREW_EDITOR: /usr/bin/nano
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: quad-core 64-bit skylake
Clang: N/A
Git: 2.41.0 => /bin/git
Curl: 7.81.0 => /bin/curl
Kernel: Linux 6.3.8-200.fc38.x86_64 x86_64 GNU/Linux
OS: Unknown
Host glibc: 2.35
/usr/bin/gcc: 11.3.0
/usr/bin/ruby: N/A
glibc: N/A
gcc@11: N/A
gcc: 13.1.0
xorg: N/A
linuxbrew@brew:~$ 
  1. I tried brew link binutils --force. Everything worked fine then.

Oh, sorry I must've missed that it solved the issue (since you didn't mark it as an answer). This seems odd to me, not sure why you had to run this command. Especially when brew doctor didn't complain.

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

Same issue here, on standard Ubuntu 20.04 server

brew config:

HOMEBREW_VERSION: 4.0.28
ORIGIN: https://github.com/Homebrew/brew
HEAD: 2b4cfb033757b63ab0b128d01c58db76480956f9
Last commit: 7 days ago
Core tap JSON: 13 Jul 02:21 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 48
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: 48-core 64-bit skylake
Clang: 16.0.6
Git: 2.41.0 => /home/linuxbrew/.linuxbrew/bin/git
Curl: 7.68.0 => /bin/curl
Kernel: Linux 5.4.0-148-generic x86_64 GNU/Linux
OS: Ubuntu 20.04.6 LTS (focal)
Host glibc: 2.31
/usr/bin/gcc: 9.4.0
/usr/bin/ruby: 2.7.0
glibc: N/A
gcc@11: N/A
gcc: N/A
xorg: N/A

The compile test:

$ cat test.c
$ gcc-13 test.c
/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so)

@osalbahr
Copy link
Sponsor Contributor

@jnooree what’s your brew doctor?

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

"ready to brew".

@osalbahr
Copy link
Sponsor Contributor

osalbahr commented Jul 13, 2023

Does running the command in Homebrew on Linux - Requirements help?

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

If you mean sudo apt-get install build-essential procps curl file git, then no, since the packages were already installed.

@osalbahr
Copy link
Sponsor Contributor

If you mean sudo apt-get install build-essential procps curl file git, then no, since the packages were already installed.

Yes that’s the command I mean. Though I doubt it’s related. I suggested it because it’s one of the first few things I do when debugging an error I get with Homebrew. Sometimes running the commands in that page fixes things for me. If they’re already installed and up to date, then running the command doesn’t hurt anyways.

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

I ran it but still got the same result.

@osalbahr
Copy link
Sponsor Contributor

osalbahr commented Jul 13, 2023

If it helps, I just tried in a distrobox create --image ubuntu:22.04 container and was unable to replicate the error. Their dockerhub image uses glibc: 2.35.

dracula@ubuntu-22-04:~$ cat test.c
#include <stdio.h>

int main()
{
  puts( "Hello, gcc-13!" );
}
dracula@ubuntu-22-04:~$ gcc-13 test.c
dracula@ubuntu-22-04:~$ ./a.out 
Hello, gcc-13!
dracula@ubuntu-22-04:~$ brew doctor
Your system is ready to brew.
dracula@ubuntu-22-04:~$ brew config
HOMEBREW_VERSION: 4.0.28
ORIGIN: https://github.com/Homebrew/brew
HEAD: 2b4cfb033757b63ab0b128d01c58db76480956f9
Last commit: 7 days ago
Core tap JSON: 13 Jul 03:47 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0
HOMEBREW_EDITOR: /usr/bin/nano
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: quad-core 64-bit skylake
Clang: N/A
Git: 2.34.1 => /bin/git
Curl: 7.81.0 => /bin/curl
Kernel: Linux 6.3.11-200.fc38.x86_64 x86_64 GNU/Linux
OS: Unknown
Host glibc: 2.35
/usr/bin/gcc: 11.3.0
/usr/bin/ruby: N/A
glibc: N/A
gcc@11: N/A
gcc: N/A
xorg: N/A

Are you by any chance able to upgrade the glibc version of your system? I would expect running apt upgrade would do that, considering the official image uses glibc: 2.35.

Regardless, this behavior is not ideal since the requirement is "Glibc 2.13 or newer" but I don't know if this error is something that Homebrew can control. Looking at gcc.rb it's not immediately clear how the linked glibc version is determined.

Maybe it just depends on the glibc version that happens to be in the GitHub Actions runner that created the bottle? Try this:

$ HOMEBREW_NO_INSTALL_FROM_API=1 brew reinstall -s gcc

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

I'm using Ubuntu 20.04, not 22.04, and 20.04 ships with glibc 2.31 (as with the OP's). I'm not sure if it is a good idea to upgrade a system glibc to an unsupported version.
Reinstalling from source should work, but I suggest that will make linuxbrew almost unusable. It will trigger rebuilding from source of all other packages (that depend on gcc).

@osalbahr
Copy link
Sponsor Contributor

osalbahr commented Jul 13, 2023

Ok, I was able to reproduce this error in a VM and apt upgrade surprisingly did not help.

osalbahr@vclvm177-128:~$ sudo apt-get install build-essential procps curl file git
Reading package lists... Done
Building dependency tree       
Reading state information... Done
file is already the newest version (1:5.38-4).
build-essential is already the newest version (12.8ubuntu1.1).
curl is already the newest version (7.68.0-1ubuntu2.18).
git is already the newest version (1:2.25.1-1ubuntu3.11).
procps is already the newest version (2:3.3.16-1ubuntu2.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
osalbahr@vclvm177-128:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
osalbahr@vclvm177-128:~$ brew doctor
Your system is ready to brew.
osalbahr@vclvm177-128:~$ file test.c
test.c: empty
osalbahr@vclvm177-128:~$ gcc-13 test.c
/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so)
collect2: error: ld returned 1 exit status
osalbahr@vclvm177-128:~$ brew config
HOMEBREW_VERSION: 4.0.28
ORIGIN: https://github.com/Homebrew/brew
HEAD: 2b4cfb033757b63ab0b128d01c58db76480956f9
Last commit: 7 days ago
Core tap JSON: 13 Jul 04:07 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: quad-core 64-bit skylake
Clang: N/A
Git: 2.25.1 => /usr/bin/git
Curl: 7.68.0 => /usr/bin/curl
Kernel: Linux 5.4.0-99-generic x86_64 GNU/Linux
OS: Ubuntu 20.04.6 LTS (focal)
Host glibc: 2.31
/usr/bin/gcc: 9.4.0
/usr/bin/ruby: 2.7.0
glibc: N/A
gcc@11: N/A
gcc: N/A
xorg: N/A

FYI, brew reinstall -s gcc did not fix it for me as I ran into an error. But I recommend trying it out regardless.

==> ../configure --prefix=/home/linuxbrew/.linuxbrew/opt/gcc --libdir=/home/linuxbrew/.linuxbrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/home/linuxbrew/.linuxbrew/opt/gmp --with-mpfr=/home/linuxbrew/.linuxbrew/opt/mpfr --with-mpc=/home/linuxbrew/.linuxbrew/opt/libmpc --with-isl=/home/linuxbrew/.linuxbrew/opt/isl --with-zstd=/home/linuxbrew/.linuxbrew/opt/zstd --with-pkgversion=Homebrew GCC 13.1.0 --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --with-boot-l
==> make
Last 15 lines from /home/osalbahr/.cache/Homebrew/Logs/gcc/02.make:
../../gcc/ggc-common.cc:1286:7: note: in expansion of macro ‘SIZE_AMOUNT’
 1286 |       SIZE_AMOUNT (MALLINFO_FN ().arena));
      |       ^~~~~~~~~~~
../../gcc/ggc-common.cc:1286:20: note: in expansion of macro ‘MALLINFO_FN’
 1286 |       SIZE_AMOUNT (MALLINFO_FN ().arena));
      |                    ^~~~~~~~~~~
make[3]: *** [Makefile:1162: ggc-common.o] Error 1
make[3]: *** Waiting for unfinished jobs....
rm gcc.pod
make[3]: Leaving directory '/tmp/gcc-20230713-2622-1k2rcl5/gcc-13.1.0/build/gcc'
make[2]: *** [Makefile:4983: all-stage1-gcc] Error 2
make[2]: Leaving directory '/tmp/gcc-20230713-2622-1k2rcl5/gcc-13.1.0/build'
make[1]: *** [Makefile:25987: stage1-bubble] Error 2
make[1]: Leaving directory '/tmp/gcc-20230713-2622-1k2rcl5/gcc-13.1.0/build'
make: *** [Makefile:1083: all] Error 2

@osalbahr
Copy link
Sponsor Contributor

Reinstalling from source should work, but I suggest that will make linuxbrew almost unusable

To the best of my knowledge, choosing to install from source is a single contained action that does not affect future usage. Otherwise, any contributor would render their linuxbrew unusable even for just testing a version bump.

It will trigger rebuilding of all other packages (that depend on gcc) from source.

I just tried it, and it only tried to reinstall gcc.

If anything, it might break things that depend on the gcc formula. But now, you don't have the gcc formula anyways. It doesn't seem to me that you'd loose anything by trying it out.

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

Ok, I'll give it a try for a workaround... But this is something should be resolved by the upstream, IMHO.

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

FYI, brew reinstall -s gcc did not fix it for me as I ran into an error. But I recommend trying it out regardless.

==> ../configure --prefix=/home/linuxbrew/.linuxbrew/opt/gcc --libdir=/home/linu
==> make
Last 15 lines from /home/osalbahr/.cache/Homebrew/Logs/gcc/02.make:
../../gcc/ggc-common.cc:1286:7: note: in expansion of macro ‘SIZE_AMOUNT’
 1286 |       SIZE_AMOUNT (MALLINFO_FN ().arena));
      |       ^~~~~~~~~~~
../../gcc/ggc-common.cc:1286:20: note: in expansion of macro ‘MALLINFO_FN’
 1286 |       SIZE_AMOUNT (MALLINFO_FN ().arena));
      |                    ^~~~~~~~~~~
make[3]: *** [Makefile:1162: ggc-common.o] Error 1
make[3]: *** Waiting for unfinished jobs....
rm gcc.pod
make[3]: Leaving directory '/tmp/gcc-20230713-29343-cgtal0/gcc-13.1.0/build/gcc'
make[2]: *** [Makefile:4983: all-stage1-gcc] Error 2
make[2]: Leaving directory '/tmp/gcc-20230713-29343-cgtal0/gcc-13.1.0/build'
make[1]: *** [Makefile:25987: stage1-bubble] Error 2
make[1]: Leaving directory '/tmp/gcc-20230713-29343-cgtal0/gcc-13.1.0/build'
make: *** [Makefile:1083: all] Error 2

Me too. It doesn't build.

@osalbahr
Copy link
Sponsor Contributor

If you want an alternative to Homebrew that does not need a high glibc version, may I interest you in spack install gcc && spack load gcc? Spack is a powerful tool that I've had good experience with on CentOS 7. I don't think you'll need such workarounds for anything other than gcc (and its dependents).

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

(Un?)suprisingly, homebrew clang does not have the same problem:

$ cat test.c
int main(void) {
    return 0;
}
$ clang test.c

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

If you want an alternative to Homebrew that does not need a high glibc version, may I interest you in spack install gcc && spack load gcc? Spack is a powerful tool that I've had good experience with on CentOS 7. I don't think you'll need such workarounds for anything other than gcc (and its dependents).

Thanks for suggestion, I'll take a look for it.

@osalbahr
Copy link
Sponsor Contributor

(Un?)suprisingly, homebrew clang does not have the same problem:

$ cat test.c
int main(void) {
    return 0;
}
$ clang test.c

That's.... interesting. Does this satisfy your use case?

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

I actually don't use homebrew gcc for my dev workflow, so it doesn't matter for me. I spotted a problem, and just wanted to fix it anyways.

@osalbahr
Copy link
Sponsor Contributor

I actually don't use homebrew gcc for my dev workflow, so it doesn't matter for me. I spotted a problem, and just wanted to fix it anyways.

Same tbh, I'm fine with the system's gcc. I actually don't even use Ubuntu 20.04 lol.

@osalbahr
Copy link
Sponsor Contributor

I'm using Ubuntu 20.04, not 22.04, and 20.04 ships with glibc 2.31

Oh. Good catch. FWIW, after using an ubuntu:20.04 container (as opposed to a VM) I can still replicate the error.

dracula@ubuntu-20-04:~$ brew doctor
Your system is ready to brew.
dracula@ubuntu-20-04:~$ gcc-13 test.c
/usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so: error loading plugin: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/linuxbrew/.linuxbrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/13/liblto_plugin.so)
collect2: error: ld returned 1 exit status
dracula@ubuntu-20-04:~$ brew config
HOMEBREW_VERSION: 4.0.28
ORIGIN: https://github.com/Homebrew/brew
HEAD: 2b4cfb033757b63ab0b128d01c58db76480956f9
Last commit: 7 days ago
Core tap JSON: 13 Jul 05:18 UTC
HOMEBREW_PREFIX: /home/linuxbrew/.linuxbrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: :0
HOMEBREW_EDITOR: /usr/bin/nano
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.10 => /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.10_1/bin/ruby
CPU: quad-core 64-bit skylake
Clang: N/A
Git: 2.25.1 => /bin/git
Curl: 7.68.0 => /bin/curl
Kernel: Linux 6.3.11-200.fc38.x86_64 x86_64 GNU/Linux
OS: Unknown
Host glibc: 2.31
/usr/bin/gcc: 9.4.0
/usr/bin/ruby: N/A
glibc: N/A
gcc@11: N/A
gcc: N/A
xorg: N/A

I'm not sure if it is a good idea to upgrade a system glibc to an unsupported version.

The error message is about missing a GLIBC_2.33 shared object (*.so). You can probably provide the shared library in LD_LIBRARY_PATH or similar. Something similar to https://stackoverflow.com/questions/72513993/how-to-install-glibc-2-29-or-higher-in-ubuntu-18-04.

@osalbahr
Copy link
Sponsor Contributor

osalbahr commented Jul 13, 2023

Also, in case someone wants another workaround that doesn't require installing from souce, it looks like the nix-shell -p gcc also works. It requires the ability to create /nix (but you can also look into `nix-portable).

Container:

dracula@ubuntu-20-04:~$ nix-shell -p gcc

[nix-shell:~]$ gcc test.c

[nix-shell:~]$ ./a.out 
Hello, gcc! (nix)

[nix-shell:~]$ gcc --version
gcc (GCC) 12.3.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Also worked in the VM:

osalbahr@vclvm177-128:~$ nix-shell -p gcc

[nix-shell:~]$ gcc test.c

[nix-shell:~]$ ./a.out 
Hello again, gcc! (nix)

But again, this is just a workaround. Ideally, "Glibc 2.13 or newer" should be enough for brew install gcc per Homebrew on Linux. Seeing that nix is able to nix-shell -p gcc, I think the reason is that nix uses its own glibc but Homebrew uses the Host's glibc (maybe by design). So this is not a bug, but maybe a warning would be nice in brew doctor (if gcc is "installed" but won't work) or a warning message when installing gcc. Alternatively, updating the docs, but doing that just for one failing formula seems like an overkill.

dracula@ubuntu-20-04:~$ nix-shell -p gcc13

[nix-shell:~]$ which -a gcc
/nix/store/rzhpy402dbc2kpk3xz87csnm0xiaw53b-gcc-wrapper-12.3.0/bin/gcc
/nix/store/6vwsydq4nzr1l8j7fyg5r61nknwq6w60-gcc-12.3.0/bin/gcc
/nix/store/iy7sgfhgdawp2privg2smaj911gx3mjd-gcc-wrapper-13.1.0/bin/gcc
/nix/store/1v2kvv6qya4ya7vd76qwfc3pj85bq182-gcc-13.1.0/bin/gcc
/usr/bin/gcc
/bin/gcc

[nix-shell:~]$ /nix/store/iy7sgfhgdawp2privg2smaj911gx3mjd-gcc-wrapper-13.1.0/bin/gcc test.c

[nix-shell:~]$ ./a.out 
Hello, gcc! (nix)

[nix-shell:~]$ ldd a.out 
	linux-vdso.so.1 (0x00007ffee95f2000)
	libc.so.6 => /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/libc.so.6 (0x00007f0d1c79f000)
	/nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib/ld-linux-x86-64.so.2 => /nix/store/3n58xw4373jp0ljirf06d8077j15pc4j-glibc-2.37-8/lib64/ld-linux-x86-64.so.2 (0x00007f0d1c987000)

@CarterLi
Copy link
Contributor Author

This issue will be fixed by not making binutils key-only. That's all.

@osalbahr
Copy link
Sponsor Contributor

This issue will be fixed by not making binutils key-only. That's all.

Oh…. True, that’s much simpler. Though I don’t know if there are any notable drawbacks for having binutils not be keg-only for everyone. I’m assuming it became a keg because it could break the system. For example brew info glibc warns that taking precedent over the system’s libraries can break things.

@jnooree
Copy link
Contributor

jnooree commented Jul 13, 2023

This issue will be fixed by not making binutils key-only. That's all.

Oh…. True, that’s much simpler. Though I don’t know if there are any notable drawbacks for having binutils not be keg-only for everyone. I’m assuming it became a keg because it could break the system. For example brew info glibc warns that taking precedent over the system’s libraries can break things.

+1. I also don't think shadowing the host toolchain is a good idea.

@LittleFall
Copy link

LittleFall commented Jul 14, 2023

another workaround: disable lto.

This may cause problems with the size and performance of the program, but it does pass compilation in my case.

g++-13 -fno-lto a.cpp

update: I copy a liblto_plugin.so from my system gcc-10 dir to homebrew gcc-13 dir. and pass the compile without -fno-lto.

@osalbahr
Copy link
Sponsor Contributor

update: I copy a liblto_plugin.so from my system gcc-10 dir to homebrew gcc-13 dir. and pass the compile without -fno-lto.

Interesting. I worry the directory might get overwritten in the next upgrade, though. You can perhaps simulate that via brew reinstall gcc.

Not sure if it is a viable fix for Homebrew to already include that file, the inner workings of gcc go over my head. If you’re familiar, you can maybe edit the formula and submit a PR.

@CarterLi
Copy link
Contributor Author

I am suprised that it can be considerred a solution.

Anyway, I am closing this issue, as it's going off topic for me.

@CarterLi CarterLi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2023
@github-actions github-actions bot added the outdated PR was locked due to age label Aug 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age
Projects
None yet
Development

No branches or pull requests

5 participants