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

ocamlopt -nodynlink does not work on armhf #8867

Closed
glondu opened this issue Aug 9, 2019 · 5 comments · Fixed by #9980
Closed

ocamlopt -nodynlink does not work on armhf #8867

glondu opened this issue Aug 9, 2019 · 5 comments · Fixed by #9980
Assignees

Comments

@glondu
Copy link
Contributor

glondu commented Aug 9, 2019

Hello,

As instructed in ocaml/dune#2527, I open an issue here.

When I compile a simple hello.ml file (Debian unstable armhf):

print_endline "Hello world!"

with ocamlopt -nodynlink hello.ml, I get relocation errors that go away when I remove -nodynlink.

Please have look at @nojb's insights in ocaml/dune#2527

@nojb
Copy link
Contributor

nojb commented Aug 9, 2019

It seems (https://sourceware.org/ml/binutils/2009-04/msg00395.html) we should not be using MOVW/MOVT to load addresses of symbols coming from PIC libraries :

ocaml/asmcomp/arm/emit.mlp

Lines 389 to 392 in 0557f07

end else if !arch > ARMv6 && not !Clflags.dlcode && !fastcode_flag then begin
` movw {emit_reg dst}, #:lower16:{emit_symbol s}\n`;
` movt {emit_reg dst}, #:upper16:{emit_symbol s}\n`;
2

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Aug 10, 2020
@xavierleroy xavierleroy removed the Stale label Aug 17, 2020
@xavierleroy xavierleroy self-assigned this Aug 17, 2020
@xavierleroy
Copy link
Contributor

A friendly bot brought this issue to my attention, one year later.

Generally speaking, ocamlopt -c -nodynlink produces code appropriate for statically-linked executables. However, OS distributions are increasingly using position-independent executables (PIE), which are not statically linked and undergo dynamic relocation at every execution.

Here I can reproduce the problem on my Raspbian rPi by using ocamlopt -ccopt -pie -nodynlink. I guess Raspbian doesn't use PIE by default yet. Likewise, I guess @glondu can make the problem go away by using ocamlopt -ccopt -no-pie -nodynlink.

We need to discuss the future of the -nodynlink option. Should it go away? Should it turn PIE off at link-time? Should it be restricted so that the generated code is still compatible with PIE even though it may not be PIC?

For ARM, not using MOVW/MOVT as suggested in #8867 (comment) would implement the third approach above, and would not have much performance impact, I guess. However, I need to check what happens with other non-x86 platforms.

@shindere
Copy link
Contributor

shindere commented Aug 17, 2020 via email

@xavierleroy
Copy link
Contributor

Results of a quick experiment: -nodynlink is incompatible with PIE on AMD64 (x86 64 bits) and ARM (32 bits). In both cases, an error is reported at link-time.

For AMD64, PIC code is generated by default, which trumps -nodynlink, so one needs to do ocamlopt -nodynlink -fno-PIC to run into the issue.

ARM64, Power, and I386 (x86 32 bits) seem OK. s390x (Z systems) doesn't support PIE at all. RISC-V could not be tested.

The appropriate action, I think, is to document that -nodynlink is incompatible with PIE and requires -ccopt -no-pie on systems that create PIEs by default.

xavierleroy added a commit to xavierleroy/ocaml that referenced this issue Oct 16, 2020
Including interactions with PIE.

Closes: ocaml#8867
emillon added a commit to emillon/dune that referenced this issue Jan 5, 2021
Closes ocaml#4069

When `dynlink:false` is passed, the ARM backend emits MOVW/MOVT
instructions which have relocations incompatible with PIC code.
This is similar to ocaml#2527 (ocaml issue: ocaml/ocaml#8867).

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this issue Jan 5, 2021
Closes ocaml#4069

When `dynlink:false` is passed, the ARM backend emits MOVW/MOVT
instructions which have relocations incompatible with PIC code.
This is similar to ocaml#2527 (ocaml issue: ocaml/ocaml#8867).

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to ocaml/dune that referenced this issue Jan 6, 2021
This is an optimization when PIC executables are not used, but this
optimization is disabled becauses it causes errors on arm32. Most
distributions are going in the direction of requiring PIC, and
`-nodynlink` might go away (see ocaml/ocaml#8867), so the supporting
code in dune (which is bypassed in most cases) can be removed.

Closes #4069
Closes #2527

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to ocaml/dune that referenced this issue Jan 6, 2021
This is an optimization when PIC executables are not used, but this
optimization is disabled becauses it causes errors on arm32. Most
distributions are going in the direction of requiring PIC, and
`-nodynlink` might go away (see ocaml/ocaml#8867), so the supporting
code in dune (which is bypassed in most cases) can be removed.

Closes #4069
Closes #2527

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to ocaml/dune that referenced this issue Jan 11, 2021
This is an optimization when PIC executables are not used, but this
optimization is disabled becauses it causes errors on arm32. Most
distributions are going in the direction of requiring PIC, and
`-nodynlink` might go away (see ocaml/ocaml#8867), so the supporting
code in dune (which is bypassed in most cases) can be removed.

Closes #4069
Closes #2527

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to ocaml/dune that referenced this issue Jan 11, 2021
This is an optimization when PIC executables are not used, but this
optimization is disabled becauses it causes errors on arm32. Most
distributions are going in the direction of requiring PIC, and
`-nodynlink` might go away (see ocaml/ocaml#8867), so the supporting
code in dune (which is bypassed in most cases) can be removed.

Closes #4069
Closes #2527

Signed-off-by: Etienne Millon <me@emillon.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants