0

I was trying to compile the following program with Homebrew g++ installed on my Mac M1:

// name: a.cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[1145140];
int main(){
    return 0;
}

The compiling command is /opt/homebrew/bin/g++-11 a.cpp. Then it reported error as follows:

/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:431:2: error: addend too big for relocation
        adrp    x0, _vec@PAGE+27483360
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: addend too big for relocation
        add     x19, x0, _vec@PAGEOFF+27483360;momd
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: fixup value out of range
        add     x19, x0, _vec@PAGEOFF+27483360;momd

I am confused at this since nothing goes wrong when this program gets compiled with clang (c++ a.cpp). I am wondering whether this is because I forget to add some compiling options, or this is a bug in g++ or something else. I will appreciate it if someone can help me.

Some information that may help:

Output of /opt/homebrew/bin/g++-11 -v:

Using built-in specs.
COLLECT_GCC=/opt/homebrew/bin/g++-11
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/11.1.0_1/libexec/gcc/aarch64-apple-darwin20/11.1.0/lto-wrapper
Target: aarch64-apple-darwin20
Configured with: ../configure --prefix=/opt/homebrew/Cellar/gcc/11.1.0_1 --libdir=/opt/homebrew/Cellar/gcc/11.1.0_1/lib/gcc/11 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-11 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 11.1.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --build=aarch64-apple-darwin20 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Homebrew GCC 11.1.0_1) 

1 Answers1

0

I can only suggest a temporal solution to this issue. Uninstall Homebrew and download the Intel version under Rosetta 2 instead. Then you can download the Intel version of GCC under Rosetta 2. It works without any problems by me, it seems to me that the M1 version of G++11 still has some bugs.

A link about how you can do this: How to run the Homebrew installer under Rosetta 2 on M1 Macbook

P. S.: I encountered an issue when trying to download the Intel version of GCC. It read that a newer version of the Xcode Command Line Tools is available and I should install them, although I have updated them to the newest version just before trying to download GCC. This can be solved very easily, just download the noted version (not the newest) of the Xcode CLT from Apple’s website, you can find the link in the log that Homebrew gives.

Dharman
  • 30,962
  • 25
  • 85
  • 135