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

OCaml 4.08beta2 fails to link on NetBSD/arm64 #8567

Closed
jaapb opened this issue Apr 1, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@jaapb
Copy link
Contributor

commented Apr 1, 2019

When compiling OCaml 4.08beta2 on a Pinebook running NetBSD (arm64 architecture), it fails with the following error message:

gmake[1]: Entering directory '/usr/pkgsrc/wip/ocaml/work/ocaml-4.08.0+beta2'
boot/ocamlrun ./ocamlopt -g -nostdlib -I stdlib -I otherlibs/dynlink  -o ocamlc.opt compilerlibs/ocamlcommon.cmxa compilerlibs/ocamlbytecomp.cmxa driver/main.cmx -cclib "-lm  -lpthread "
ld: stdlib/libasmrun.a(arm64.o): in function `caml_raise_exn':
(.text+0x324): relocation truncated to fit: R_AARCH64_LDST64_ABS_LO12_NC against symbol `caml_backtrace_active' defined in .bss section in stdlib/libasmrun.a(backtrace_n.o)
ld: (.text+0x324): warning: one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
ld: stdlib/libasmrun.a(arm64.o): in function `caml_raise_exception':
(.text+0x374): relocation truncated to fit: R_AARCH64_LDST64_ABS_LO12_NC against symbol `caml_backtrace_active' defined in .bss section in stdlib/libasmrun.a(backtrace_n.o)
ld: (.text+0x374): warning: one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
File "caml_startup", line 1:
Error: Error during linking

I'm using the package available at https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=tree;f=ocaml which adds a few local patches, but nothing that I can see would cause this. It does patch configure to recognise NetBSD/aarch64 as an arm64 architecture that has dynamic linking.

Ocaml 4.07 compiles fine with a similar patch.

I've seen issue #6283 - but that seems to occur in a different part in the tree, and I've checked that the changes applied in that issue are still there.

@gasche

This comment has been minimized.

Copy link
Member

commented Apr 1, 2019

This may be related to the recent alignment-fix #8557 , which was merged in trunk but not, I think, in the 4.08 release branch (and wouldn't be in beta2 anyway). Would you mind trying to build the trunk on your machine and report if that works?

@mshinwell

This comment has been minimized.

Copy link
Contributor

commented Apr 1, 2019

Is this happening because caml_backtrace_active is defined as a 32-bit quantity in runtime/backtrace.c, but being loaded using an instruction whose relocation expects a 64-bit-aligned address, in runtime/arm64.S (e.g. line 419)?

@jaapb

This comment has been minimized.

Copy link
Contributor Author

commented Apr 1, 2019

@xavierleroy

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

@mshinwell is right, the wrong instructions are used to access caml_backtrace_active. The problem should show up as a link-time error when the linker puts caml_backtrace_active at an address = 4 mod 8. It may also result in backtraces being stashed while caml_backtrace_active is actually 0.

I have been unable to force the Linux linker to do the 4 mod 8 placement, but apparently the NetBSD one can do it. The fix #8557 changes the placement of global data, so it can hide the problem, but is not a proper fix.

xavierleroy added a commit to xavierleroy/ocaml that referenced this issue Apr 2, 2019

arm64.S: use 32-bit load to access caml_backtrace_active
`caml_backtrace_active` is declared with type `int32_t`, so it is
incorrect to access it with a 64-bit "ldr" instruction.
Either a link-time error occurs, as in issue ocaml#8567,
or the wrong value may be loaded.

This commit uses `ldrsh` instructions (32-bit signed loads) to
access `caml_backtrace_active`.

Closes: ocaml#8567
@xavierleroy

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

Proposed fix: #8569

xavierleroy added a commit that referenced this issue Apr 2, 2019

arm64.S: use 32-bit loads to access caml_backtrace_active (#8569)
`caml_backtrace_active` is declared with type `int32_t`, so it is
incorrect to access it with a 64-bit "ldr" instruction.
Either a link-time error occurs, as in issue #8567,
or the wrong value may be loaded.

This commit uses `ldrsw` instructions (32-bit signed loads) to
access `caml_backtrace_active`.

Closes: #8567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.