`-flat_namespace` linking issue when cross-compiling GMP-based library for macOS x86_64 on arm64
Andrej Zhilenkov
azhilenkov at gmail.com
Thu Oct 30 15:09:17 CET 2025
Hello!
Unsure if my issue is part of
https://gmplib.org/list-archives/gmp-bugs/2024-October/005539.html or
it's something else,
but still might be worth reporting (at least traceback will be
googlable and might lead someone to the conclusions quicker).
I've encountered an error trying to cross compile Python extension
that's using GMP on arm64 machine for x86_64 macOS target.
The error looks like this:
```
ld: branch8 out of range 366651 in ___gmpn_add_nc
final section layout:
__TEXT addr=0x00000000, size=0x02d09000, fileOffset=0x00000000
__text addr=0x00001400, size=0x0264a5e4, fileOffset=0x00001400
__stubs addr=0x0264b9e4, size=0x0000423c, fileOffset=0x0264b9e4
__stub_helper addr=0x0264fc20, size=0x00006c58, fileOffset=0x0264fc20
__gcc_except_tab addr=0x02656878, size=0x002efc04, fileOffset=0x02656878
__const addr=0x02946480, size=0x001cdc18, fileOffset=0x02946480
__cstring addr=0x02b140a0, size=0x0014324b, fileOffset=0x02b140a0
__unwind_info addr=0x02c572ec, size=0x0008d2d0, fileOffset=0x02c572ec
__eh_frame addr=0x02ce45c0, size=0x00024a30, fileOffset=0x02ce45c0
__DATA_CONST addr=0x02d09000, size=0x0022b000, fileOffset=0x02d09000
__got addr=0x02d09000, size=0x00001dc8, fileOffset=0x02d09000
__mod_init_func addr=0x02d0adc8, size=0x00000690, fileOffset=0x02d0adc8
__const addr=0x02d0b460, size=0x00227fd0, fileOffset=0x02d0b460
__DATA addr=0x02f34000, size=0x000c3000, fileOffset=0x02f34000
__la_symbol_ptr addr=0x02f34000, size=0x000056a0, fileOffset=0x02f34000
__data addr=0x02f396a0, size=0x0005f7b8, fileOffset=0x02f396a0
__thread_vars addr=0x02f98e58, size=0x000006d8, fileOffset=0x02f98e58
__thread_ptrs addr=0x02f99530, size=0x00000178, fileOffset=0x02f99530
__thread_data addr=0x02f996b0, size=0x000000d8, fileOffset=0x02f996b0
__thread_bss addr=0x02f99790, size=0x00018850, fileOffset=0x02f99790
__bss addr=0x02fb1fe0, size=0x0003b0c0, fileOffset=0x00000000
__common addr=0x02fed0a0, size=0x00009098, fileOffset=0x00000000
__LINKEDIT addr=0x02ff7000, size=0x0148e000, fileOffset=0x02fb2000
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
Investigating and trying to narrow it down, I've found that the issue
is unrelated to Python itself -
it can be reproduced by compiling any library that uses GMP and using
the `-flat-namespace` flag during the linking.
I've created a repo that reproduced the issue using Github Workflow.
See - https://github.com/Andrej730/test-gmp-mac-cross-compilation/actions/runs/18943199817/job/54087191838
Backup pastebin - https://pastebin.com/pB0SntM0
I'm not exactly sure if I do need the `-flat-namespace` flag in my
case - we were using `-Wl,-flat_namespace,-undefined,suppress` for
ages now when compiling that Python extension and maybe it's not
needed anymore.
Reading through previous thread I've found that `-flat-namespace` and
`-undefined suppress` are somehow connected historically and since
`-undefined suppress` is officially deprecated (clang prints a warning
when it's used), then maybe switching to `-undefined dynamic_lookup`
will do the trick without `-flat-namespace`.
So I'll try to disable it for now as a workaround for this issue.
Any thoughts on this? Is it the same issue as in the thread linked
above and perhaps the issue with `-flat_namespace` can be
noted either on "Known Build Problems" / "Notes for Particular
System"? Or is it something else worth investigating?
Thanks for your time and for maintaining GMP.
More information about the gmp-bugs
mailing list