-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
ldc2 with -g flag fails to link on Apple M1 Pro (aarch64) with unaligned pointer #3864
Comments
Some sleuthing reveals that This latter command works, even with the same object file. The first number of that argument is the min platform version. |
As a workaround, if I set the |
I guess ld64 pedantically checks DWARF alignment specs and complains about an invalid one; I guess alignment of pointer itself vs. pointee alignment or something along these lines. |
As clang doesn't seem to either. This *might* fix ldc-developers#3864.
As clang doesn't seem to either. This *might* fix ldc-developers#3864.
Thx for testing, Steven. 2nd guess: Lines 40 to 50 in 5a28329
(testable via |
That seems to have worked. However, I now do not have file/line numbers as I did when targeting MacOS 11. steves@MacBook-Pro objdraw % export MACOSX_DEPLOYMENT_TARGET=11
steves@MacBook-Pro objdraw % cat testthrow.d
void foo()
{
throw new Exception("hi");
}
void main()
{
foo();
}
steves@MacBook-Pro objdraw % ldc2 -g testthrow.d
steves@MacBook-Pro objdraw % ./testthrow
object.Exception@testthrow.d(3): hi
----------------
testthrow.d:3 void testthrow.foo() [0x1021d422b]
testthrow.d:8 _Dmain [0x1021d4237]
steves@MacBook-Pro objdraw % ldc2 -g -preserve-dwarf-line-section=false testthrow.d
steves@MacBook-Pro objdraw % ./testthrow
object.Exception@testthrow.d(3): hi
----------------
??:? void testthrow.foo() [0x10062022b]
??:? _Dmain [0x100620237]
steves@MacBook-Pro objdraw % unset MACOSX_DEPLOYMENT_TARGET
steves@MacBook-Pro objdraw % ldc2 -g testthrow.d
ld: warning: pointer not aligned at address 0x100294081 (anon + 129 from testthrow.o)
ld: unaligned pointer(s) for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
steves@MacBook-Pro objdraw % ldc2 -g -preserve-dwarf-line-section=false testthrow.d
steves@MacBook-Pro objdraw % ./testthrow
object.Exception@testthrow.d(3): hi
----------------
??:? void testthrow.foo() [0x104820c5b]
??:? _Dmain [0x104820c67] |
Thx for testing again - great, so that's it. Apple might have changed the linker scripts in more recent SDKs then. Note that this is a LLVM-hack on our side, as workaround for a druntime limitation (cannot use default .dSYM files) tracked in https://issues.dlang.org/show_bug.cgi?id=20510. |
OK. For now, I guess I will stick with my original workaround, since i get line/file data out of it. |
A question about the "LLVM hack". Is that with the switch or default behavior? Because I would think it's good for the default ldc2 to actually link on MacOS Monterey. |
The hack is enabled by default - as it wasn't known to cause trouble and provides the expected file/line infos. Changing that logic depending on target macOS version probably requires specifying a versioned macOS triple via |
Scratch that, my old macbook pro is too old to receive the update. Someone else would have to test x64 |
That said, @Geod24 seems to have started a .dSYM implementation, so it might make more sense to push that rather than wasting time on hack applicability detection here. |
It works fine on x86-64. |
LDC will then need to start producing .dSYM files. |
I thought that's what ld64 does by default (at least with Line 112 in 5a28329
|
I answered in the PR. |
@Geod24 Possible to sponsor https://issues.dlang.org/show_bug.cgi?id=20510 in order to have #3864 fixed? Contact me for testing x86_64 or arm64 binaries, macOS Monterey (arm64/Rosetta) and 10.14 (x86_64) installed here. |
I sadly don't have too much time for LDC development these days, but feel free to ping me if you need any testing as well – just got a M1 Max/Monterey box. |
I now too have an M1 Macbook Air, so can test too. Off topic: Already ran into troubles of course :). For now, I managed to build LDC (arm64 binary) by setting
simply rerunning cmake "fixes" it, and happily finishes. |
I cannot reproduce this on M1 Macbook Air with LDC master My local LDC is built by setting MACOSX_DEPLOYMENT_TARGET=11 (only when running cmake, not when executing the tests below, as you can see from the first line) and using the LDC 1.27.1 arm64 released binary as bootstrapping compiler.
No errors. The released LDC 1.27.1 arm64 binaries do indeed not work:
Building LDC 1.27.1 locally:
So perhaps something wrong in the way the LDC 1.27.1 release package is made? |
Hmm, I guessing |
Extra info: if I use my self-built ldc-1.27.1 to again build ldc-1.27.1, I no longer need |
@JohanEngelen what's the deployment target of that binary? If you run |
On the binaries produced by the new LDC (that does not have the -g problem discussed here):
|
The prebuilt LDC 1.27.0 has |
Does |
1.30.0 does not work with the release build does work, even without that set. Using |
Naive question: why does the front end matter? That is, I assume other LLVM based compilers (Rust and Clang etc.) don't have this problem, and yet I thought it was the backend that ultimately produced the object code that is apparently offensive to the linker. |
I think LDC uses a modified backend, see notes above. |
Did you use that for compilation as stated there, or just for linking? It needs to be disabled when compiling to disable the only relevant LDC-specific LLVM mod here. |
hm... I didn't know it would be a linker flag. I used it in compilation. |
So when you say "it needs to be disabled", do you mean the flag shouldn't be used during compilation, or that it is used during compilation to disable the mod? |
It only affects compilation, so you need to use/disable it when compiling all stuff linked to the final executable. If you do that, you should get vanilla LLVM codegen, where I definitely don't expect the alignment linker errors. Are you still testing the dummy executable from the original post, without any (non-C) deps linked at all? (The error would still be expected when linking with |
I added the flag in to the |
Aha, so a dub build. I recommend using the DFLAGS env variable to enforce a flag for all compilations of a dub build, incl. rebuilding dependencies. (It might not affect the dub linker cmdlines though, but that doesn't matter here). And yes, there's |
Success! What can I expect not to work correctly with that flag enabled? |
You don't get file/line infos in druntime exception backtraces, because druntime requires that DWARF data in the binary itself, while IIRC LLVM or ld64 moved to NOT preserving it for the linked executable. (To be loaded from the original object files / static lib archives directly via .dSYM indirection or so as far as I gathered - but I don't know anything about Apple's ecosystem.) |
@schveiguy IIRC there was a feature added recently to Dub which allows you to pass flags down to dependencies. |
Here's the full description for those that are interested: The linker on macOS will remove any debug info, i.e. every section with the Normally the linker removes all the debug info but adds a reference to the object files. The debugger can then read the object files to get filename and line number information. It's also possible to use an additional tool that generates a separate |
|
macOS 13 released. |
I'm trying LDC 1.28 + macOS 13.0 Ventura + -g + Xcode 14.0.1 and so far the error is completely unchanged.
I admit I have not fully followed and don't know if there is a workaround. |
|
... this is completely unrelated. |
How to build it? |
You got a reply on the forum: https://forum.dlang.org/post/tmgbro$1b3u$1@digitalmars.com. If in doubt, use an official LDC release from GitHub; no idea about the homebrew stuff. |
I'm working on this, got something implemented that uses |
zoujiaqing@mac server % which dub
/Users/zoujiaqing/Programs/ldc/bin/dub
zoujiaqing@mac server % dub --version
DUB version 1.29.0, built on Jul 20 2022
zoujiaqing@mac server % ldc2 --version
LDC - the LLVM D compiler (1.30.0):
based on DMD v2.100.1 and LLVM 14.0.3
built with LDC - the LLVM D compiler (1.30.0)
Default target: arm64-apple-darwin22.1.0
Host CPU: cyclone
http://dlang.org - http://wiki.dlang.org/LDC
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
avr - Atmel AVR Microcontroller
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
hexagon - Hexagon
lanai - Lanai
mips - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc32le - PowerPC 32 LE
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
ve - VE
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
zoujiaqing@mac server % ~/Programs/ldc/bin/dub run
Performing "debug" build using /Users/zoujiaqing/Programs/ldc/bin/ldc2 for aarch64, arm_hardfloat.
taggedalgebraic 0.11.22: target for configuration "library" is up to date.
eventcore 0.9.20+commit.4.g6744ae7: target for configuration "cfrunloop" is up to date.
server ~master: building configuration "application"...
Linking...
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: alignment (1) of atom 'anon' is too small and may result in unaligned pointers
ld: warning: pointer not aligned at address 0x100334231 ('anon' + 561 from .dub/build/application-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-A117F359EB78BC810BDE4A43C61EA410/server.o)
ld: warning: pointer not aligned at address 0x1003350DB ('anon' + 2025 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.driver.o))
ld: warning: pointer not aligned at address 0x1003398EB ('anon' + 1759 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.driver.o))
ld: warning: pointer not aligned at address 0x10033B426 ('anon' + 696 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.events.o))
ld: warning: pointer not aligned at address 0x10033C2A1 ('anon' + 618 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.kqueue.o))
ld: warning: pointer not aligned at address 0x10033C942 ('anon' + 1186 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.pipes.o))
ld: warning: pointer not aligned at address 0x10033EE5E ('anon' + 1258 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.processes.o))
ld: warning: pointer not aligned at address 0x100342E2A ('anon' + 872 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.sockets.o))
ld: warning: pointer not aligned at address 0x1003479E2 ('anon' + 630 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.posix.watchers.o))
ld: warning: pointer not aligned at address 0x100349562 ('anon' + 1437 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.threadedfile.o))
ld: warning: pointer not aligned at address 0x10034B9F2 ('anon' + 1597 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.drivers.timer.o))
ld: warning: pointer not aligned at address 0x10034D833 ('anon' + 372 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.internal.consumablequeue.o))
ld: warning: pointer not aligned at address 0x10034E57E ('anon' + 244 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.internal.dlist.o))
ld: warning: pointer not aligned at address 0x10034EC95 ('anon' + 1228 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.internal.ioworker.o))
ld: warning: pointer not aligned at address 0x100351681 ('anon' + 4868 from ../../eventcore/.dub/build/cfrunloop-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-3845054F4A360DA6EC39A6439A220013/libeventcore.a(eventcore.internal.utils.o))
ld: warning: pointer not aligned at address 0x10036F251 ('anon' + 270 from ../../../.dub/packages/taggedalgebraic-0.11.22/taggedalgebraic/.dub/build/library-debug-posix.osx.darwin-aarch64.arm_hardfloat-ldc_v1.30.0-642115DE0E516005CED050361BF5F15F/libtaggedalgebraic.a(taggedalgebraic.o))
ld: unaligned pointer(s) for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
/Users/zoujiaqing/Programs/ldc/bin/ldc2 failed with exit code 1. I used it, but couldn't build it. Add zoujiaqing@mac server % dub run --build=plain
Performing "plain" build using /Users/zoujiaqing/Programs/ldc/bin/ldc2 for aarch64, arm_hardfloat.
taggedalgebraic 0.11.22: target for configuration "library" is up to date.
eventcore 0.9.20+commit.4.g6744ae7: target for configuration "cfrunloop" is up to date.
server ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Running server
Edit source/app.d to start your project. Thanks @schveiguy @kinke and every one! |
…n backtraces. (#4291) * macOS debuginfo: add support for using `atos` to get file:line info in backtraces. Resolves issue #3864 * Return to LLVM default of emitting __debug_line section in __DWARF segment as a debug section (not regular) * Re-enable test now that issue #3280 is fixed. * Allow full path names in exception file:line debug output. * Allow full path names in exception file:line debug output. * Add changelog entry
Fixed by PR linked above. |
I removed everything I could think of:
The text was updated successfully, but these errors were encountered: