Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD64 Dynamic Linking and Shared Libraries #3763

Closed
vicuna opened this issue Aug 17, 2005 · 1 comment
Closed

AMD64 Dynamic Linking and Shared Libraries #3763

vicuna opened this issue Aug 17, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 17, 2005

Original bug ID: 3763
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Alexander Bottema
Version: 3.08.3
OS: Linux 2.6.8
Submission from: b.mathworks.com (144.212.95.8)

Given that test.ml is:
print_string "Hello World";;

Then type:

ocamlopt –output-obj –o test_obj.o test.ml
ocamlmklib –o test test_obj.o

You'll the following error message from the linker:

/usr/bin/ld: test_obj.o: relocation R_X86_64_32S against `caml_curry2_1' can not
be used when making a shared object; recompile with -fPIC
test_obj.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

I investigated this a little bit further and it is clear from the emitter
(asmcomp/amd64/emit.mlp) and the assembly runtime (asmrun/amd64.S) is not
producing position independent code for AMD64. I tried to fix this, but it was
more challenging than I initially thought. The problem is to produce the correct
code that uses both the PCGOTREL and PLT sections. Furthermore, the runtime C
library itself needs to be compiled with -fPIC.

One issue I had is to know whether symbol references are referencing data or
functions. An alternative solution would be to have all functions be accessed
through function pointers and then access everything through GOT, but then the
function pointers need to be properly initialized before used.

After a day or two I realized that this is too complicated to be resolved
easily, so I hope someone with better experience of the inner workings of AMD64
can take a look at this.

@vicuna
Copy link
Author

vicuna commented Oct 13, 2005

Comment author: administrator

Added option ocamlopt -fPIC in 3.09. Not turned on by default (as well as
-fPIC for compiling asmrun) because unsure about performance impact. XL,
2005-10-13

@vicuna vicuna closed this as completed Oct 13, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant