iains / gcc-12-branch

GCC 12 for Darwin with experimental Arm64 support. Current release 12.4-darwin-r0 [June 2024]
GNU General Public License v2.0
24 stars 7 forks source link

error: unexpected token in '.section' directive #17

Closed magnified103 closed 1 year ago

magnified103 commented 1 year ago

I'm trying to build this snippet under GCC 12.2 (homebrew) on macOS 13

#include <vector>

std::vector<int> arr[100000];

int main() {}

Build:

$ g++-12 -o main main.cpp
/var/folders/bc/8mk4ndsx2zl7qxxvdnjccr540000gn/T//ccXt4STq.s:445:29: error: unexpected token in '.section' directive
        .section .data.rel.ro.local

It seems that the error does not occur with -O2 flag.

g++-12 -v ```shell Using built-in specs. COLLECT_GCC=g++-12 COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/12.2.0/bin/../libexec/gcc/aarch64-apple-darwin22/12/lto-wrapper Target: aarch64-apple-darwin22 Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/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=-12 --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 12.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin22 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Homebrew GCC 12.2.0) ```
iains commented 1 year ago

confirmed.

It looks like the code (at O0) saves the end position of the array as a constant (.data.rel.ro.local is constant data section on ELF, but not for Mach-O). At O1 and above the value is computed in-line (so that it does not try to create the constant in that section).

Oddly, it looks like we compute the end address of smaller arrays in-line even at O0 (so it will be a case of tracking down where this decision is made, and then making sure that we emit a suitable section designator for macOS / Mach-O).

Season0518 commented 1 year ago

This issue still exists on gcc13. I have attempted to downgrade to gcc11 and the issue has been resolved.

iains commented 1 year ago

fixed on this branch now.