delocate: accept more directive expressions
For example, openssl/asm_base.h expands to include the line .long ((1 << 0) | (1 << 1)); when BTI and PAC are enabled. Change-Id: I07208e0430757721e97b88c706672375f8f58f1f Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/62525 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com>
This commit is contained in:
committed by
Boringssl LUCI CQ
parent
f86dd18593
commit
ab45f42e8e
@@ -263,6 +263,47 @@ func (d *delocation) processDirective(statement, directive *node32) (*node32, er
|
||||
return statement, nil
|
||||
}
|
||||
|
||||
func (d *delocation) processSymbolExpr(expr *node32, b *strings.Builder) bool {
|
||||
changed := false
|
||||
assertNodeType(expr, ruleSymbolExpr)
|
||||
|
||||
for expr != nil {
|
||||
atom := expr.up
|
||||
assertNodeType(atom, ruleSymbolAtom)
|
||||
|
||||
for term := atom.up; term != nil; term = skipWS(term.next) {
|
||||
if term.pegRule == ruleSymbolExpr {
|
||||
changed = d.processSymbolExpr(term, b) || changed
|
||||
continue
|
||||
}
|
||||
|
||||
if term.pegRule != ruleLocalSymbol {
|
||||
b.WriteString(d.contents(term))
|
||||
continue
|
||||
}
|
||||
|
||||
oldSymbol := d.contents(term)
|
||||
newSymbol := d.mapLocalSymbol(oldSymbol)
|
||||
if newSymbol != oldSymbol {
|
||||
changed = true
|
||||
}
|
||||
|
||||
b.WriteString(newSymbol)
|
||||
}
|
||||
|
||||
next := skipWS(atom.next)
|
||||
if next == nil {
|
||||
break
|
||||
}
|
||||
assertNodeType(next, ruleSymbolOperator)
|
||||
b.WriteString(d.contents(next))
|
||||
next = skipWS(next.next)
|
||||
assertNodeType(next, ruleSymbolExpr)
|
||||
expr = next
|
||||
}
|
||||
return changed
|
||||
}
|
||||
|
||||
func (d *delocation) processLabelContainingDirective(statement, directive *node32) (*node32, error) {
|
||||
// The symbols within directives need to be mapped so that local
|
||||
// symbols in two different .s inputs don't collide.
|
||||
@@ -280,24 +321,12 @@ func (d *delocation) processLabelContainingDirective(statement, directive *node3
|
||||
for node = skipWS(node.up); node != nil; node = skipWS(node.next) {
|
||||
assertNodeType(node, ruleSymbolArg)
|
||||
arg := node.up
|
||||
var mapped string
|
||||
assertNodeType(arg, ruleSymbolExpr)
|
||||
|
||||
for term := arg; term != nil; term = term.next {
|
||||
if term.pegRule != ruleLocalSymbol {
|
||||
mapped += d.contents(term)
|
||||
continue
|
||||
}
|
||||
var b strings.Builder
|
||||
changed = d.processSymbolExpr(arg, &b) || changed
|
||||
|
||||
oldSymbol := d.contents(term)
|
||||
newSymbol := d.mapLocalSymbol(oldSymbol)
|
||||
if newSymbol != oldSymbol {
|
||||
changed = true
|
||||
}
|
||||
|
||||
mapped += newSymbol
|
||||
}
|
||||
|
||||
args = append(args, mapped)
|
||||
args = append(args, b.String())
|
||||
}
|
||||
|
||||
if !changed {
|
||||
@@ -1260,6 +1289,16 @@ func writeAarch64Function(w stringWriter, funcName string, writeContents func(st
|
||||
w.WriteString(".type " + funcName + ", @function\n")
|
||||
w.WriteString(funcName + ":\n")
|
||||
w.WriteString(".cfi_startproc\n")
|
||||
// We insert a landing pad (`bti c` instruction) unconditionally at the beginning of
|
||||
// every generated function so that they can be called indirectly (with `blr` or
|
||||
// `br x16/x17`). The instruction is encoded in the HINT space as `hint #34` and is
|
||||
// a no-op on machines or program states not supporting BTI (Branch Target Identification).
|
||||
// None of the generated function bodies call other functions (with bl or blr), so we only
|
||||
// insert a landing pad instead of signing and validating $lr with `paciasp` and `autiasp`.
|
||||
// Normally we would also generate a .note.gnu.property section to annotate the assembly
|
||||
// file as BTI-compatible, but if the input assembly files are BTI-compatible, they should
|
||||
// already have those sections so there is no need to add an extra one ourselves.
|
||||
w.WriteString("\thint #34 // bti c\n")
|
||||
writeContents(w)
|
||||
w.WriteString(".cfi_endproc\n")
|
||||
w.WriteString(".size " + funcName + ", .-" + funcName + "\n")
|
||||
|
||||
@@ -47,17 +47,14 @@ QuotedText <- (EscapedChar / [^"])*
|
||||
LabelContainingDirective <- LabelContainingDirectiveName WS SymbolArgs
|
||||
LabelContainingDirectiveName <- ".xword" / ".word" / ".long" / ".set" / ".byte" / ".8byte" / ".4byte" / ".quad" / ".tc" / ".localentry" / ".size" / ".type" / ".uleb128" / ".sleb128"
|
||||
SymbolArgs <- SymbolArg ((WS? ',' WS?) SymbolArg)*
|
||||
SymbolShift <- ('<<' / '>>') WS? [0-9]+
|
||||
SymbolArg <- (OpenParen WS?)? (
|
||||
Offset /
|
||||
SymbolType /
|
||||
(Offset / LocalSymbol / SymbolName / Dot) (WS? Operator WS? (Offset / LocalSymbol / SymbolName))* /
|
||||
LocalSymbol TCMarker? /
|
||||
SymbolName Offset /
|
||||
SymbolName TCMarker?)
|
||||
(WS? CloseParen)? (WS? SymbolShift)?
|
||||
|
||||
SymbolArg <- SymbolExpr
|
||||
SymbolExpr <- SymbolAtom (WS? SymbolOperator WS? SymbolExpr)?
|
||||
SymbolAtom <- Offset / SymbolType / LocalSymbol TCMarker? / SymbolName Offset / SymbolName TCMarker? / Dot / OpenParen WS? SymbolExpr WS? CloseParen
|
||||
SymbolOperator <- '+' / '-' / '|' / '<<' / '>>'
|
||||
OpenParen <- '('
|
||||
CloseParen <- ')'
|
||||
|
||||
SymbolType <- [@%] ('function' / 'object')
|
||||
Dot <- '.'
|
||||
TCMarker <- '[TC]'
|
||||
|
||||
+2494
-2530
File diff suppressed because it is too large
Load Diff
@@ -145,6 +145,7 @@ BORINGSSL_bcm_text_end:
|
||||
.type bcm_redirector_remote_function, @function
|
||||
bcm_redirector_remote_function:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
b remote_function
|
||||
.cfi_endproc
|
||||
.size bcm_redirector_remote_function, .-bcm_redirector_remote_function
|
||||
@@ -153,6 +154,7 @@ bcm_redirector_remote_function:
|
||||
.type bcm_redirector_y0, @function
|
||||
bcm_redirector_y0:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
b y0
|
||||
.cfi_endproc
|
||||
.size bcm_redirector_y0, .-bcm_redirector_y0
|
||||
@@ -161,6 +163,7 @@ bcm_redirector_y0:
|
||||
.type bcm_redirector_y12, @function
|
||||
bcm_redirector_y12:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
b y12
|
||||
.cfi_endproc
|
||||
.size bcm_redirector_y12, .-bcm_redirector_y12
|
||||
@@ -169,6 +172,7 @@ bcm_redirector_y12:
|
||||
.type bss_symbol_bss_get, @function
|
||||
bss_symbol_bss_get:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
adrp x0, .Lbss_symbol_local_target
|
||||
add x0, x0, :lo12:.Lbss_symbol_local_target
|
||||
ret
|
||||
@@ -179,6 +183,7 @@ bss_symbol_bss_get:
|
||||
.type .Lboringssl_loadgot_stderr, @function
|
||||
.Lboringssl_loadgot_stderr:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
adrp x0, :got:stderr
|
||||
ldr x0, [x0, :got_lo12:stderr]
|
||||
ret
|
||||
@@ -189,6 +194,7 @@ bss_symbol_bss_get:
|
||||
.type .LOPENSSL_armcap_P_addr, @function
|
||||
.LOPENSSL_armcap_P_addr:
|
||||
.cfi_startproc
|
||||
hint #34 // bti c
|
||||
adrp x0, OPENSSL_armcap_P
|
||||
add x0, x0, :lo12:OPENSSL_armcap_P
|
||||
ret
|
||||
|
||||
@@ -93,7 +93,7 @@ bar:
|
||||
# assumption that it's too small to hold a pointer. But Clang
|
||||
# will store offsets in it.
|
||||
# WAS .byte (.LBB231_40-.LBB231_19)>>2, 4, .Lfoo, (.Lfoo), .Lfoo<<400, ( .Lfoo ) << 66
|
||||
.byte (.LBB231_40_BCM_1-.LBB231_19_BCM_1)>>2, 4, .Lfoo_BCM_1, (.Lfoo_BCM_1), .Lfoo_BCM_1<<400, ( .Lfoo_BCM_1 ) << 66
|
||||
.byte (.LBB231_40_BCM_1-.LBB231_19_BCM_1)>>2, 4, .Lfoo_BCM_1, (.Lfoo_BCM_1), .Lfoo_BCM_1<<400, (.Lfoo_BCM_1)<<66
|
||||
.byte 421
|
||||
.text
|
||||
.loc 1 2 0
|
||||
|
||||
Reference in New Issue
Block a user