Stream: git-wasmtime

Topic: wasmtime / PR #2558 x64: support PC-rel symbol references...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:14):

cfallin opened PR #2558 from pic-symbol-refs to main:

The new x64 backend, up till now, was generating references to non-colocated symbols using Abs8 relocations (i.e., place the absolute 64-bit address in a 64-bit immediate to an instruction).

This works fine on Linux/x86-64, even in .sos as generated by Lucet, but is not actually what we want to do when the is_pic flag is set. macOS is more strict and fails to link object files generated with these Abs8 relocations. Instead, we need to use the GOT (global offset table).

This PR changes the lowering of func_addr/symbol_addr/call with non-colocated symbols to use a PC-relative load from the GOT instead, and emits the special GOTPCRel4 relocation type. This is equivalent to (in gas syntax) a movq symbol@GOTPCREL(%rip), %dest instruction.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:14):

cfallin requested pchickey for a review on PR #2558.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:35):

bjorn3 submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:35):

bjorn3 created PR Review Comment:

i32::min_value()?

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:47):

cfallin updated PR #2558 from pic-symbol-refs to main:

The new x64 backend, up till now, was generating references to non-colocated symbols using Abs8 relocations (i.e., place the absolute 64-bit address in a 64-bit immediate to an instruction).

This works fine on Linux/x86-64, even in .sos as generated by Lucet, but is not actually what we want to do when the is_pic flag is set. macOS is more strict and fails to link object files generated with these Abs8 relocations. Instead, we need to use the GOT (global offset table).

This PR changes the lowering of func_addr/symbol_addr/call with non-colocated symbols to use a PC-relative load from the GOT instead, and emits the special GOTPCRel4 relocation type. This is equivalent to (in gas syntax) a movq symbol@GOTPCREL(%rip), %dest instruction.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:48):

cfallin submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 06:48):

cfallin created PR Review Comment:

Done -- actually -i32::MAX is more clear (since it's a positive i32 passed as an immediate to sub).

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 18:02):

pchickey submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 08 2021 at 18:03):

cfallin merged PR #2558.


Last updated: Nov 22 2024 at 16:03 UTC