www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Relocation error

reply SealabJaster <sealabjaster gmail.com> writes:
I'm currently working on a libc-less standard library for myself, 
and was working on Posix support recently.

However, I'm now running into the following linker error that I 
really don't know what to do with:

```
/usr/bin/ld: 
.dub/build/test-debug-linux.posix-x86_64-dmd_v2.097.1-6FDCEE655D9685908188
B42E500F838/libd.o: relocation R_X86_64_32 against symbol
`_D7runtime10entrypoint13g_programArgsS4libd14datastructures5array__T5ArrayTAxaSQBp6memory9allocator15systemallocator15SystemAllocatorSQDsQDq6growth__T6GrowthVii0S_DQEwQEuQBe__T6GrowToVmi8ZQmFNaNbNiNfZSQGhQGfQCp__T6GrowBySQHbQGzQDj__TQCfVmi8ZQCnFNbNiZ9__lambda1ZQBwVii8S_DQIzQIxQFh__T11GrowByScaleVmi2ZQsFNaNbNiNfZSQKqQKoQGy__TQEjSQLgQLeQHo__TQChVmi2ZQCpFN
NiZQEfZQFuZQIjZQLr' can not be used when making a PIE object; recompile with
-fPIE
collect2: error: ld returned 1 exit status
```

I've uploaded the current state of the code [1] in case anyone 
has the free time to check it out, because I have 0 clue on how 
to solve this as I'm mostly a windows dev, and this is only 
happening on linux.

Using DMD 2.097, Ubuntu 20.24 on WSL2, ld 2.34.

p.s. I thought I'd end up saying the opposite, but the win32 API 
is much nicer so far.

[1] https://github.com/BradleyChatha/bcstd
Aug 04 2021
next sibling parent SealabJaster <sealabjaster gmail.com> writes:
On Wednesday, 4 August 2021 at 18:52:40 UTC, SealabJaster wrote:
 ...
Forgot to mention: Build with `dub run --compiler=dmd -c test`
Aug 04 2021
prev sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Wednesday, 4 August 2021 at 18:52:40 UTC, SealabJaster wrote:
 However, I'm now running into the following linker error that I 
 really don't know what to do with:

 ```
 /usr/bin/ld: 
 .dub/build/test-debug-linux.posix-x86_64-dmd_v2.097.1-6FDCEE655D9685908188
B42E500F838/libd.o: relocation R_X86_64_32 against symbol [...] can not be used
when making a PIE object; recompile with -fPIE
 collect2: error: ld returned 1 exit status
 ```
You need to add `-fPIC` to your `dflags`. Normally this is done automatically by `/etc/dmd.conf`, but you've disabled that with `-conf=`.
Aug 04 2021
parent reply SealabJaster <sealabjaster gmail.com> writes:
On Wednesday, 4 August 2021 at 19:47:42 UTC, Paul Backus wrote:
 ...
I am now getting this error: ``` /usr/bin/ld: -f may not be used without -shared ``` Adding -shared: ``` /usr/bin/ld: .dub/build/test-debug-linux.posix-x86_64-dmd_v2.097.1-3DC2262935789AAE4203 53EDDD1C5A4/libd.o: relocation R_X86_64_32 against symbol `_D7runtime10entrypoint13g_programArgsS4libd14datastructures5array__T5ArrayTAxaSQBp6memory9allocator15systemallocator15SystemAllocatorSQDsQDq6growth__T6GrowthVii0S_DQEwQEuQBe__T6GrowToVmi8ZQmFNaNbNiNfZSQGhQGfQCp__T6GrowBySQHbQGzQDj__TQCfVmi8ZQCnFNbNiZ9__lambda1ZQBwVii8S_DQIzQIxQFh__T11GrowByScaleVmi2ZQsFNaNbNiNfZSQKqQKoQGy__TQEjSQLgQLeQHo__TQChVmi2ZQCpFN NiZQEfZQFuZQIjZQLr' can not be used when making a shared object; recompile with -fPIC ``` -fPIE gives the exact same results.
Aug 04 2021
parent SealabJaster <sealabjaster gmail.com> writes:
On Wednesday, 4 August 2021 at 20:24:28 UTC, SealabJaster wrote:
 ..
Oops, please ignore, put it into lflags instead of dflags
Aug 04 2021