<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110186>110186</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`ld.lld` fails to link librararies/executables with a name longer than 8 characters targeting `aarch64-w64-mingw32`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Martchus
</td>
</tr>
</table>
<pre>
The title of this issue sounds strange, but I somehow managed to get myself into this problem:
```
$ /usr/bin/clang main.c -v -fuse-ld=lld -target aarch64-w64-mingw32 -Xclang -triple -Xclang aarch64-w64-mingw32 -rtlib=compiler-rt -shared -o 123456789
clang version 18.1.8
Target: aarch64-w64-windows-gnu
Thread model: posix
InstalledDir: /usr/bin
"/usr/bin/clang-18" -cc1 -triple aarch64-w64-windows-gnu -emit-obj -mrelax-all -dumpdir 123456789- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -fno-use-init-array -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -target-abi aapcs -debugger-tuning=gdb -fdebug-compilation-dir=/run/media/devel/projects/c++/misc -v -fcoverage-compilation-dir=/run/media/devel/projects/c++/misc -resource-dir /usr/lib/clang/18 -internal-isystem /usr/lib/clang/18/include -internal-isystem /usr/aarch64-w64-mingw32/include -internal-isystem /usr/aarch64-w64-mingw32/usr/include -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -exception-model=seh -fcolor-diagnostics -triple aarch64-w64-mingw32 -faddrsig -o /tmp/main-9ea098.o -x c main.c
clang -cc1 version 18.1.8 based upon LLVM 18.1.8 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/aarch64-w64-mingw32/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/clang/18/include
/usr/aarch64-w64-mingw32/include
End of search list.
"/usr/bin/ld.lld" -m arm64pe --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o 123456789.exe /usr/aarch64-w64-mingw32/lib/dllcrt2.o /usr/aarch64-w64-mingw32/lib/crtbegin.o -L/usr/aarch64-w64-mingw32/lib -L/usr/aarch64-w64-mingw32/mingw/lib -L/usr/lib/clang/18/lib/windows /tmp/main-9ea098.o -lmingw32 /usr/lib/clang/18/lib/windows/libclang_rt.builtins-aarch64.a -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 /usr/lib/clang/18/lib/windows/libclang_rt.builtins-aarch64.a -lmoldname -lmingwex -lmsvcrt -lkernel32 /usr/aarch64-w64-mingw32/lib/crtend.o
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
With `main.c`:
```
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello world!");
return 0;
}
```
When removing the `9` (so the library name becomes just `12345678`) the program compiles and links. Not sure whether it runs as I am not sure how to test this (on my x86_64 GNU/Linux system).
---
This is likely a problem caused by me doing something stupid when setting up the toolchain. I am currently trying to use [LLVM](https://gitlab.archlinux.org/archlinux/packaging/packages/llvm/-/blob/main/PKGBUILD?ref_type=heads)/[clang](https://gitlab.archlinux.org/archlinux/packaging/packages/clang/-/blob/main/PKGBUILD?ref_type=heads)/[lld](https://gitlab.archlinux.org/archlinux/packaging/packages/lld/-/blob/main/PKGBUILD?ref_type=heads) as provided by Arch Linux to cross compile for `aarch64-w64-mingw32`. For this I built [binutils](https://github.com/Martchus/PKGBUILDs/blob/master/binutils/mingw-w64-clang-aarch64/PKGBUILD), mingw-w64 [headers](https://github.com/Martchus/PKGBUILDs/blob/master/headers/mingw-w64-clang-aarch64/PKGBUILD) and [crt](https://github.com/Martchus/PKGBUILDs/blob/master/crt/mingw-w64-clang-aarch64/PKGBUILD) and the [compiler runtime for the aarch64-w64-mingw32 target](https://github.com/Martchus/PKGBUILDs/blob/master/compiler-rt/mingw-w64-clang-aarch64/PKGBUILD). You can click the links to see what versions I built and how I invoked the builds exactly. Then I tried to build [libc++](https://github.com/Martchus/PKGBUILDs/blob/master/libc++/mingw-w64-clang-aarch64/PKGBUILD). It compiled until the linking of `libunwind.dll` - which has a name longer than 8 characters:
```
FAILED: lib/libunwind.dll lib/libunwind.dll.a
: && /usr/lib/ccache/bin/clang -rtlib=compiler-rt -fuse-ld=lld -mguard=cf -target aarch64-w64-mingw32 -Xclang -triple -Xclang aarch64-w64-mingw32 -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -Wformat -Werror=format-security -rtlib=compiler-rt -fuse-ld=lld -mguard=cf -target aarch64-w64-mingw32 -Xclang -triple -Xclang aarch64-w64-mingw32 -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-O1,--sort-common,--as-needed -fstack-protector -Wl,-O1,--sort-common,--as-needed -fstack-protector -rtlib=compiler-rt -nostdlib++ --unwindlib=none -shared -o lib/libunwind.dll -Wl,--out-implib,lib/libunwind.dll.a -Wl,--major-image-version,1,--minor-image-version,0 libunwind/src/CMakeFiles/unwind_shared_objects.dir/libunwind.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-EHABI.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-seh.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindLevel1.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindLevel1-gcc-ext.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-sjlj.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-wasm.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindRegistersRestore.S.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindRegistersSave.S.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && :
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: misaligned ldr/str offset
ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```
I tried to invoke the command manually (outside of CMake) and could reproduce the problem. It also didn't work without `ccache`. I tried to strip down the command a lot. Removing none of the many options helped. Eventually I noticed that all I need to do to get passed this error is to make the library name shorter. The following command worked:
```
/usr/bin/clang -rtlib=compiler-rt -fuse-ld=lld -mguard=cf -target aarch64-w64-mingw32 -Xclang -triple -Xclang aarch64-w64-mingw32 -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -Wformat -Werror=format-security -rtlib=compiler-rt -fuse-ld=lld -mguard=cf -target aarch64-w64-mingw32 -Xclang -triple -Xclang aarch64-w64-mingw32 -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-O1,--sort-common,--as-needed -fstack-protector -Wl,-O1,--sort-common,--as-needed -fstack-protector -rtlib=compiler-rt -nostdlib++ --unwindlib=none -shared -o lib/libfoo.dll -Wl,--out-implib,lib/libfoo.dll.a -Wl,--major-image-version,1,--minor-image-version,0 libunwind/src/CMakeFiles/unwind_shared_objects.dir/libunwind.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-EHABI.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-seh.cpp.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindLevel1.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindLevel1-gcc-ext.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-sjlj.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/Unwind-wasm.c.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindRegistersRestore.S.obj libunwind/src/CMakeFiles/unwind_shared_objects.dir/UnwindRegistersSave.S.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
```
I find that very strange. I am not very familiar with linker internals but probably the section where the library name is stored cannot be aligned correctly if it exceeds a certain size. Am I doing something wrong in the way I am trying to setup the toolchain?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl9z4ziO_zTKC4oqW0rczkMekjieTV3P9FX_ucw-dVEkJLFDkTqSsuP99FcgJduZcXfndlK7-5CqlCORIASQIPADSO69agziVXZxk12szvgQWuuufuUuiHbwZ5WVu6vPLUJQQSPYGkKrPCjvBwRvByM9-OC4aTArbqEaAtyDtx22dgsdN7xBCcFCgwG6nUddgzLBJi69s5XGLiuvs9kqm02_i9n4l16Lc8iK9eBdVqwrZbJiLTQ3DXRcmVwA2wCrB49My6xcaS2BBe7oe5w70S7O2XZxzjplmm1ZAPs9DWbBqV7j_v0krQtaVVm5ErbrlUbHXADmW-5QArMwL8rzi8W75WUSNDHaoPPKGpgv83m-TD2fozxZef3sM1tlpN161phhJGsdcgmdlaiJuLdePaWue-MD1xrlSjnqejYhkQKyojg1TWy-zIoCmBDzvdLfkQIYdiowW30D1jnU_IlxrYHJoeulcgd9GTCpPK80stohAhMauWPcB1ZhbR2yiotHNPJAp_WmYxt0qlboYrPgTrIN1wMywzv0wGhBWa10ativL4liBQ_KGhbnBnolgPVKMI0b1FAA62rHO2S9VSagy8qVsQaB1R0PLUPnjAVW1z0T1gTHRcjKlTXAamOZIyNWpmFEC6wT1vjgBhGsY1wr7qNonWeVCrVCLT3Zm6F5Y4F081m5KhIvMkNlVGDcOb6bDJGJfoAGDTqSe2yrkYfBIWTFzWbJTzXXPeOu2yxP9Rkk8cd2XingvBcemMRqaB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