Skip to content

Commit

Permalink
Support medium memory models.
Browse files Browse the repository at this point in the history
With `-mcmodel=medium`, Clang may emit loads of the GOT address.
Delocate needs to handle that in order to avoid a relocation inside the
module.

Bug: b:316210772
Change-Id: I55eb2711860e43f68de131e28538aef9f5ce1889
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64791
Auto-Submit: Adam Langley <agl@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
  • Loading branch information
agl authored and Boringssl LUCI CQ committed Dec 15, 2023
1 parent b251d81 commit 7460d74
Show file tree
Hide file tree
Showing 5 changed files with 1,476 additions and 1,321 deletions.
16 changes: 16 additions & 0 deletions util/fipstools/delocate/delocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,22 @@ Args:

args = append(args, argStr)

case ruleGOTAddress:
if instructionName != "leaq" {
return nil, fmt.Errorf("_GLOBAL_OFFSET_TABLE_ used outside of lea")
}
if i != 0 || len(argNodes) != 2 {
return nil, fmt.Errorf("Load of _GLOBAL_OFFSET_TABLE_ address didn't have expected form")
}
d.gotDeltaNeeded = true
changed = true
targetReg := d.contents(argNodes[1])
args = append(args, ".Lboringssl_got_delta(%rip)")
wrappers = append(wrappers, func(k func()) {
k()
d.output.WriteString(fmt.Sprintf("\taddq .Lboringssl_got_delta(%%rip), %s\n", targetReg))
})

case ruleGOTLocation:
if instructionName != "movabsq" {
return nil, fmt.Errorf("_GLOBAL_OFFSET_TABLE_ lookup didn't use movabsq")
Expand Down
3 changes: 2 additions & 1 deletion util/fipstools/delocate/delocate.peg
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ LocalLabel <- [0-9][0-9$]*
LocalLabelRef <- [0-9][0-9$]*[bf]
Instruction <- InstructionName (WS InstructionArg ((WS? ',' WS?) InstructionArg)*)?
InstructionName <- [[A-Z]][[A-Z.0-9]]* [.+\-]?
InstructionArg <- IndirectionIndicator? (ARMConstantTweak / RegisterOrConstant / LocalLabelRef / TOCRefHigh / TOCRefLow / GOTLocation / GOTSymbolOffset / MemoryRef) AVX512Token*
InstructionArg <- IndirectionIndicator? (ARMConstantTweak / RegisterOrConstant / LocalLabelRef / TOCRefHigh / TOCRefLow / GOTLocation / GOTAddress / GOTSymbolOffset / MemoryRef) AVX512Token*
GOTLocation <- '$_GLOBAL_OFFSET_TABLE_-' LocalSymbol
GOTAddress <- '_GLOBAL_OFFSET_TABLE_(%rip)'
GOTSymbolOffset <- ('$' SymbolName '@GOT' 'OFF'?) / (":got:" SymbolName)
AVX512Token <- WS? '{' '%'? [0-9a-z]* '}'
TOCRefHigh <- '.TOC.-' ('0b' / ('.L' [a-zA-Z_0-9]+)) "@ha"
Expand Down
Loading

0 comments on commit 7460d74

Please sign in to comment.