delocate: use 64-bit GOT offsets in the large memory model.

I tried to save space and use 32-bit GOT offsets since a GOT > 2GiB is
crazy. However, Clang's linker emits 64-bit relocations even for .long,
thus the four bytes following each offset get stomped. It mostly works
because the relocations are applied in order, thus the following
relocation gets stomped but is then processed and fixed. But there's
four bytes of stomp at the end which hits the module integrity hash,
which is fatal.

This could be fixed by adding four bytes of padding after the list of
offsets, but that's piling a hack on a hack. So this change just
switches to 64-bit offsets.

Change-Id: I227eec67c481d93a414fbed19aa99471f9df0f0e
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/42484
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
chromium-5359
Adam Langley 5 years ago committed by CQ bot account: commit-bot@chromium.org
parent 430ccd6163
commit 56308910f3
  1. 14
      util/fipstools/delocate/delocate.go
  2. 8
      util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s

@ -1271,12 +1271,10 @@ Args:
changed = true changed = true
wrappers = append(wrappers, func(k func()) { wrappers = append(wrappers, func(k func()) {
// While the compiler output supports 64-bit offsets in the GOT, // Even if one tries to use 32-bit GOT offsets, Clang's linker (at the time
// https://refspecs.linuxbase.org/elf/x86_64-abi-0.98.pdf page 70, footnote // of writing) emits 64-bit relocations anyway, so the following four bytes
// 3 says that the GOT is limited to 32 bits. It's not clear about // get stomped. Thus we use 64-bit offsets.
// signed/unsigned but a GOT with more than 2^31 entries seems implausible d.output.WriteString(fmt.Sprintf("\tmovq .Lboringssl_%s_%s(%%rip), %s\n", prefix, symbol, targetReg))
// so we save the extra space.
d.output.WriteString(fmt.Sprintf("\tmovsl .Lboringssl_%s_%s(%%rip), %s\n", prefix, symbol, targetReg))
}) })
default: default:
@ -1573,11 +1571,11 @@ func transform(w stringWriter, inputs []inputFile) error {
for _, name := range sortedSet(d.gotOffsetsNeeded) { for _, name := range sortedSet(d.gotOffsetsNeeded) {
w.WriteString(".Lboringssl_got_" + name + ":\n") w.WriteString(".Lboringssl_got_" + name + ":\n")
w.WriteString("\t.long " + name + "@GOT\n") w.WriteString("\t.quad " + name + "@GOT\n")
} }
for _, name := range sortedSet(d.gotOffOffsetsNeeded) { for _, name := range sortedSet(d.gotOffOffsetsNeeded) {
w.WriteString(".Lboringssl_gotoff_" + name + ":\n") w.WriteString(".Lboringssl_gotoff_" + name + ":\n")
w.WriteString("\t.long " + name + "@GOTOFF\n") w.WriteString("\t.quad " + name + "@GOTOFF\n")
} }
} }

@ -13,7 +13,7 @@ BORINGSSL_bcm_text_start:
addq $.Lboringssl_got_delta-.L0, %rcx addq $.Lboringssl_got_delta-.L0, %rcx
addq %rax, %rcx addq %rax, %rcx
# WAS movabsq $_Z1gv@GOTOFF, %rax # WAS movabsq $_Z1gv@GOTOFF, %rax
movsl .Lboringssl_gotoff__Z1gv(%rip), %rax movq .Lboringssl_gotoff__Z1gv(%rip), %rax
addq %rcx, %rax addq %rcx, %rax
jmpq *%rax jmpq *%rax
@ -27,7 +27,7 @@ BORINGSSL_bcm_text_start:
addq $.Lboringssl_got_delta-.L0$pb, %rcx addq $.Lboringssl_got_delta-.L0$pb, %rcx
addq %rax, %rcx addq %rax, %rcx
# WAS movabsq $h@GOT, %rax # WAS movabsq $h@GOT, %rax
movsl .Lboringssl_got_h(%rip), %rax movq .Lboringssl_got_h(%rip), %rax
movq (%rcx,%rax), %rax movq (%rcx,%rax), %rax
movl (%rax), %eax movl (%rax), %eax
retq retq
@ -55,9 +55,9 @@ OPENSSL_ia32cap_addr_delta:
.Lboringssl_got_delta: .Lboringssl_got_delta:
.quad _GLOBAL_OFFSET_TABLE_-.Lboringssl_got_delta .quad _GLOBAL_OFFSET_TABLE_-.Lboringssl_got_delta
.Lboringssl_got_h: .Lboringssl_got_h:
.long h@GOT .quad h@GOT
.Lboringssl_gotoff__Z1gv: .Lboringssl_gotoff__Z1gv:
.long _Z1gv@GOTOFF .quad _Z1gv@GOTOFF
.type BORINGSSL_bcm_text_hash, @object .type BORINGSSL_bcm_text_hash, @object
.size BORINGSSL_bcm_text_hash, 64 .size BORINGSSL_bcm_text_hash, 64
BORINGSSL_bcm_text_hash: BORINGSSL_bcm_text_hash:

Loading…
Cancel
Save