Skip to content

Commit

Permalink
Read FIPS hash address using adrp instead of adr to increase reach
Browse files Browse the repository at this point in the history
This change extends #1332
to `BORINGSSL_bcm_text_hash` symbol.
  • Loading branch information
dkostic committed Jul 31, 2024
1 parent 181eb7d commit f3ada4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
17 changes: 10 additions & 7 deletions util/fipstools/delocate/delocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func (d *delocation) processAarch64Instruction(statement, instruction *node32) (
symbol, offset, _, didChange, symbolIsLocal, _ := d.parseMemRef(arg.up)
changed = didChange

if isFipsScopeMarkers(symbol) {
if isFipsMarker(symbol) {
// fips scope markers are known. But they challenge the adr
// reach, so go through GOT via an adrp outside the scope.
redirector := redirectorName(symbol)
Expand Down Expand Up @@ -1953,9 +1953,12 @@ func transform(w stringWriter, includes []string, inputs []inputFile, startEndDe
w.WriteString(fmt.Sprintf(".loc %d 1 0\n", maxObservedFileNumber+1))
}
if d.processor == aarch64 {
// Grab the address of BORINGSSL_bcm_test_[start,end] via a relocation
// Grab the address of BORINGSSL_bcm_text_[start,end,hash] via a relocation
// from a redirector function. For this to work, need to add the markers
// to the symbol table.
w.WriteString(fmt.Sprintf(".global BORINGSSL_bcm_text_hash\n"))
w.WriteString(fmt.Sprintf(".type BORINGSSL_bcm_text_hash, @function\n"))

w.WriteString(fmt.Sprintf(".global BORINGSSL_bcm_text_start\n"))
w.WriteString(fmt.Sprintf(".type BORINGSSL_bcm_text_start, @function\n"))
}
Expand Down Expand Up @@ -2410,10 +2413,9 @@ func localEntryName(name string) string {

func isSynthesized(symbol string, processor processorType) bool {
SymbolisSynthesized := strings.HasSuffix(symbol, "_bss_get") ||
symbol == "OPENSSL_ia32cap_get" ||
symbol == "BORINGSSL_bcm_text_hash"
symbol == "OPENSSL_ia32cap_get"

// While BORINGSSL_bcm_text_[start,end] are known symbols, on aarch64 we go
// While BORINGSSL_bcm_text_[start,end,hash] are known symbols, on aarch64 we go
// through the GOT because adr doesn't have adequate reach.
if processor != aarch64 {
SymbolisSynthesized = SymbolisSynthesized || strings.HasPrefix(symbol, "BORINGSSL_bcm_text_")
Expand All @@ -2422,9 +2424,10 @@ func isSynthesized(symbol string, processor processorType) bool {
return SymbolisSynthesized
}

func isFipsScopeMarkers(symbol string) bool {
func isFipsMarker(symbol string) bool {
return symbol == "BORINGSSL_bcm_text_start" ||
symbol == "BORINGSSL_bcm_text_end"
symbol == "BORINGSSL_bcm_text_end" ||
symbol == "BORINGSSL_bcm_text_hash"
}

func redirectorName(symbol string) string {
Expand Down
1 change: 1 addition & 0 deletions util/fipstools/delocate/testdata/aarch64-Basic/in.s
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ foo:
// Ensure BORINGSSL_bcm_text_[end,start] are loaded through GOT
adrp x4, :got:BORINGSSL_bcm_text_start
adrp x5, :got:BORINGSSL_bcm_text_end
adrp x6, :got:BORINGSSL_bcm_text_hash

local_function:

Expand Down
20 changes: 20 additions & 0 deletions util/fipstools/delocate/testdata/aarch64-Basic/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
.global BORINGSSL_bcm_text_hash
.type BORINGSSL_bcm_text_hash, @function
.global BORINGSSL_bcm_text_start
.type BORINGSSL_bcm_text_start, @function
BORINGSSL_bcm_text_start:
Expand Down Expand Up @@ -158,6 +160,13 @@ foo:
mov x5, x0
ldp x0, x30, [sp], #16
add sp, sp, 128
// WAS adrp x6, :got:BORINGSSL_bcm_text_hash
sub sp, sp, 128
stp x0, x30, [sp, #-16]!
bl .Lboringssl_loadgot_BORINGSSL_bcm_text_hash
mov x6, x0
ldp x0, x30, [sp], #16
add sp, sp, 128

.Llocal_function_local_target:
local_function:
Expand Down Expand Up @@ -225,6 +234,17 @@ bss_symbol_bss_get:
.cfi_endproc
.size .Lboringssl_loadgot_BORINGSSL_bcm_text_end, .-.Lboringssl_loadgot_BORINGSSL_bcm_text_end
.p2align 2
.hidden .Lboringssl_loadgot_BORINGSSL_bcm_text_hash
.type .Lboringssl_loadgot_BORINGSSL_bcm_text_hash, @function
.Lboringssl_loadgot_BORINGSSL_bcm_text_hash:
.cfi_startproc
hint #34 // bti c
adrp x0, :got:BORINGSSL_bcm_text_hash
ldr x0, [x0, :got_lo12:BORINGSSL_bcm_text_hash]
ret
.cfi_endproc
.size .Lboringssl_loadgot_BORINGSSL_bcm_text_hash, .-.Lboringssl_loadgot_BORINGSSL_bcm_text_hash
.p2align 2
.hidden .Lboringssl_loadgot_BORINGSSL_bcm_text_start
.type .Lboringssl_loadgot_BORINGSSL_bcm_text_start, @function
.Lboringssl_loadgot_BORINGSSL_bcm_text_start:
Expand Down

0 comments on commit f3ada4f

Please sign in to comment.