Open
Description
Repro:
$ git clone https://git.musl-libc.org/git/musl
$ cd musl
$ ./configure --prefix=$PWD/build/x32 --target=x86_64-linux-muslx32 AR="llvm-ar" CC="clang" RANLIB="llvm-ranlib" CFLAGS="--target=x86_64-linux-muslx32 -fuse-ld=lld"
$ make -j$(nproc)
You should see link errors like this:
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/exit/atexit.lo
>>> referenced by atexit.c
>>> obj/src/exit/atexit.lo:(__atexit_lockptr)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/linux/membarrier.lo
>>> referenced by membarrier.c
>>> obj/src/linux/membarrier.lo:(.data.rel.ro..L__const.__membarrier.sa+0x0)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/c_locale.lo
>>> referenced by c_locale.c
>>> obj/src/locale/c_locale.lo:(__c_dot_utf8)
ld.lld: error: relocation R_X86_64_32 cannot be used against symbol '__c_dot_utf8'; recompile with -fPIC
>>> defined in obj/src/locale/c_locale.lo
>>> referenced by c_locale.c
>>> obj/src/locale/c_locale.lo:(__c_dot_utf8_locale)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/dcngettext.lo
>>> referenced by dcngettext.c
>>> obj/src/locale/dcngettext.lo:(__gettext_lockptr)
ld.lld: error: relocation R_X86_64_32 cannot be used against symbol '__locale_lock'; recompile with -fPIC
>>> defined in obj/src/locale/locale_map.lo
>>> referenced by locale_map.c
>>> obj/src/locale/locale_map.lo:(__locale_lockptr)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/malloc/lite_malloc.lo
>>> referenced by lite_malloc.c
>>> obj/src/malloc/lite_malloc.lo:(__bump_lockptr)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in obj/src/locale/localeconv.lo
>>> referenced by localeconv.c
>>> obj/src/locale/localeconv.lo:(posix_lconv)
In case it's helpful:
❯ llvm-readelf -sr obj/src/locale/localeconv.lo
Relocation section '.rela.text.localeconv' at offset 0x10c contains 1 entries:
Offset Info Type Sym. Value Symbol's Name + Addend
00000002 00000402 R_X86_64_PC32 00000000 .data.rel.ro.posix_lconv - 4
Relocation section '.rela.data.rel.ro.posix_lconv' at offset 0x118 contains 10 entries:
Offset Info Type Sym. Value Symbol's Name + Addend
00000000 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 0
00000004 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000008 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
0000000c 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000010 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000014 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000018 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
0000001c 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000020 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
00000024 0000030a R_X86_64_32 00000000 .rodata.str1.1 + 2
Symbol table '.symtab' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 FILE LOCAL DEFAULT ABS localeconv.c
2: 00000000 56 OBJECT LOCAL DEFAULT 6 posix_lconv
3: 00000000 0 SECTION LOCAL DEFAULT 5 .rodata.str1.1
4: 00000000 0 SECTION LOCAL DEFAULT 6 .data.rel.ro.posix_lconv
5: 00000000 7 FUNC GLOBAL DEFAULT 3 localeconv
I'm labeling this as an LLD bug, but for all I know it could be an LLVM backend bug too; please relabel if needed.