dmalloc icon indicating copy to clipboard operation
dmalloc copied to clipboard

"make shlib" doesn't work on lld on FreeBSD, etc (needs to be recompiled with -fPIC)

Open ngie-eign opened this issue 2 months ago • 1 comments

I suspect this issue occurs with other linkers and Linux as well.

% ld --version
LLD 19.1.7 (FreeBSD llvmorg-19.1.7-0-gcd708029e0b2-1400007) (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2) (compatible with GNU linkers)
% gcc --version
gcc (FreeBSD Ports Collection) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% g++ --version
g++ (FreeBSD Ports Collection) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
rm -f libdmalloc.so libdmalloc.so.t
ld -shared --whole-archive -soname libdmalloc.so -o libdmalloc.so.t libdmalloc.a
ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_low'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:112 (/usr/home/ngie/git/dmalloc/heap.c:112)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_low'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:113 (/usr/home/ngie/git/dmalloc/heap.c:113)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_high'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:116 (/usr/home/ngie/git/dmalloc/heap.c:116)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_high'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:117 (/usr/home/ngie/git/dmalloc/heap.c:117)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_flags'; recompile with -fPIC
>>> defined in libdmalloc.a(error.o)
>>> referenced by heap.c:120 (/usr/home/ngie/git/dmalloc/heap.c:120)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_high'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:121 (/usr/home/ngie/git/dmalloc/heap.c:121)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_low'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:121 (/usr/home/ngie/git/dmalloc/heap.c:121)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:121 (/usr/home/ngie/git/dmalloc/heap.c:121)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_flags'; recompile with -fPIC
>>> defined in libdmalloc.a(error.o)
>>> referenced by heap.c:103 (/usr/home/ngie/git/dmalloc/heap.c:103)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol 'dmalloc_errno'; recompile with -fPIC
>>> defined in libdmalloc.a(user_malloc.o)
>>> referenced by heap.c:108 (/usr/home/ngie/git/dmalloc/heap.c:108)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:109 (/usr/home/ngie/git/dmalloc/heap.c:109)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '_dmalloc_heap_low'; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:112 (/usr/home/ngie/git/dmalloc/heap.c:112)
>>>               heap.o:(heap_extend) in archive libdmalloc.a

ld: error: relocation R_X86_64_32 cannot be used against local symbol; recompile with -fPIC
>>> defined in libdmalloc.a(heap.o)
>>> referenced by heap.c:104 (/usr/home/ngie/git/dmalloc/heap.c:104)
>>>               heap.o:(heap_extend) in archive libdmalloc.a
...

ngie-eign avatar Oct 22 '25 21:10 ngie-eign

FreeBSD solves this by building separate objects for shared and static linkage purposes and specifying -fPIC appropriately.

ngie-eign avatar Oct 22 '25 21:10 ngie-eign