Odin
Odin copied to clipboard
`-build-mode:shared` fails on Linux with `ld` error `recompile with -fPIC`.
Context
Odin doesn't build a shared libary on Linux.
- Operating System: Ubuntu 20.04 LTS
- Please paste
odin versionoutput: odin version dev-2021-08:40b4f3a9
Expected Behavior
I expect Odin to successfully build a .so file when invoked with -build-mode:shared and at least one procedure was tagged with @export.
Current Behavior
$ odin build . -build-mode:shared
ld: /mnt/w/odin-test/odin-test.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
Minimum repro case
Compile using odin build . -build-mode:shared. Creates a .dll on Windows as expected, creates .o file but doesn't create the desired .so file at the end.
package minrep
@export foozle :: proc "c" () -> (res: int) {
return 42;
}
main :: proc () {
}
Can confirm this, also happens with -build-mode:obj during the following ld call. -extra-linker-flags:-fPIE solves this but unsure whether it's the intended way or even does what I want, as afaik there shouldn't be 32 bit relocations in pure 64 bit code?
Also I couldn't test the resulting object yet because of that I somehow failed to decouple the runtime (-no-crt working??)
odin version dev-2021-08:0e84e06
I additionally get ld: Error: unable to disambiguate: -arch (did you mean --arch ?), which I assume means I have an incompatible version of ld/lld. When I build to object (odin build . -build-mode:object) and then link manually (cc -shared abc.o), I get the -fPIC error, as mentioned above: /usr/bin/ld: abc.o: relocation R_X86_64_32S against '.rodata' can not be used when making a shared object; recompile with -fPIC.
I guess a solution to this would be to add position independent compilation as an explicit compiler flag
Fixes were made yesterday. Do you still have these issues on HEAD?
Thanks for the quick reply. It does indeed work now, I didn't notice that I didn't do a successful pull. So I guess we can close this now. I'm very grateful it works now, I've been waiting for this for a while :)
I consider it closed provisionally. Will test it tomorrow with tests\core\math\big's library for the Linux CI. But it's promising.
Should I close this?
Should I close this? I'll close it tomorrow after I verify it successfully builds and runs the big maths tests on Linux.
Hello!
I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue
- open a PR referencing and resolving the issue;
- leave a comment on it and discuss ideas how you could contribute towards resolving it;
- leave a comment and describe in detail why this issue is critical for your use case;
- open a new issue with updated details and a plan on resolving the issue.
The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..