"addend too big for relocation" error reported by Homebrew g++ installed on Mac M1

  c++, g++, macos

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, [email protected]+27483360
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: addend too big for relocation
        add     x19, x0, [email protected]+27483360;momd
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: fixup value out of range
        add     x19, x0, [email protected]+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) 

Source: Windows Questions C++

LEAVE A COMMENT