Browse Source

delocate: put emitted labels in a specific file.

Otherwise Clang has to assign a file entry to the label which conflicts with
later, explicit, file entries.

Change-Id: Ifc782821517aa7b48ba3ef304d4468f2bc850ac2
Reviewed-on: https://boringssl-review.googlesource.com/27544
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
kris/onging/CECPQ3_patch15
Adam Langley 6 years ago
committed by CQ bot account: commit-bot@chromium.org
parent
commit
6f6a237d46
11 changed files with 71 additions and 2 deletions
  1. +41
    -2
      util/fipstools/delocate.go
  2. +3
    -0
      util/fipstools/testdata/ppc64le-GlobalEntry/out.s
  3. +3
    -0
      util/fipstools/testdata/ppc64le-LoadToR0/out.s
  4. +3
    -0
      util/fipstools/testdata/ppc64le-Sample/out.s
  5. +3
    -0
      util/fipstools/testdata/ppc64le-Sample2/out.s
  6. +3
    -0
      util/fipstools/testdata/ppc64le-TOCWithOffset/out.s
  7. +3
    -0
      util/fipstools/testdata/x86_64-BSS/out.s
  8. +3
    -0
      util/fipstools/testdata/x86_64-Basic/out.s
  9. +3
    -0
      util/fipstools/testdata/x86_64-GOTRewrite/out.s
  10. +3
    -0
      util/fipstools/testdata/x86_64-LabelRewrite/out.s
  11. +3
    -0
      util/fipstools/testdata/x86_64-Sections/out.s

+ 41
- 2
util/fipstools/delocate.go View File

@@ -1158,6 +1158,11 @@ func transform(w stringWriter, inputs []inputFile) error {
symbols := make(map[string]struct{})
// localEntrySymbols contains all symbols with a .localentry directive.
localEntrySymbols := make(map[string]struct{})
// fileNumbers is the set of IDs seen in .file directives.
fileNumbers := make(map[int]struct{})
// maxObservedFileNumber contains the largest seen file number in a
// .file directive. Zero is not a valid number.
maxObservedFileNumber := 0

for _, input := range inputs {
forEachPath(input.ast.up, func(node *node32) {
@@ -1186,6 +1191,35 @@ func transform(w stringWriter, inputs []inputFile) error {
}
localEntrySymbols[symbol] = struct{}{}
}, ruleStatement, ruleLabelContainingDirective)

forEachPath(input.ast.up, func(node *node32) {
assertNodeType(node, ruleLocationDirective)
directive := input.contents[node.begin:node.end]
if !strings.HasPrefix(directive, ".file") {
return
}
parts := strings.Fields(directive)
if len(parts) == 2 {
// This is a .file directive with just a
// filename. Clang appears to generate just one
// of these at the beginning of the output for
// the compilation unit. Ignore it.
return
}
fileNo, err := strconv.Atoi(parts[1])
if err != nil {
panic(fmt.Sprintf("Failed to parse file number from .file: %q", directive))
}

if _, ok := fileNumbers[fileNo]; ok {
panic(fmt.Sprintf("Duplicate file number %d observed", fileNo))
}
fileNumbers[fileNo] = struct{}{}

if fileNo > maxObservedFileNumber {
maxObservedFileNumber = fileNo
}
}, ruleStatement, ruleLocationDirective)
}

processor := x86_64
@@ -1204,7 +1238,10 @@ func transform(w stringWriter, inputs []inputFile) error {
gotExternalsNeeded: make(map[string]struct{}),
}

w.WriteString(".text\nBORINGSSL_bcm_text_start:\n")
w.WriteString(".text\n")
w.WriteString(fmt.Sprintf(".file %d \"inserted_by_delocate.c\"\n", maxObservedFileNumber + 1))
w.WriteString(fmt.Sprintf(".loc %d 1 0\n", maxObservedFileNumber + 1))
w.WriteString("BORINGSSL_bcm_text_start:\n")

for _, input := range inputs {
if err := d.processInput(input); err != nil {
@@ -1212,7 +1249,9 @@ func transform(w stringWriter, inputs []inputFile) error {
}
}

w.WriteString(".text\nBORINGSSL_bcm_text_end:\n")
w.WriteString(".text\n")
w.WriteString(fmt.Sprintf(".loc %d 2 0\n", maxObservedFileNumber + 1))
w.WriteString("BORINGSSL_bcm_text_end:\n")

// Emit redirector functions. Each is a single jump instruction.
var redirectorNames []string


+ 3
- 0
util/fipstools/testdata/ppc64le-GlobalEntry/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
@@ -19,6 +21,7 @@ foo:

bl
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.LBORINGSSL_external_toc:
.quad .TOC.-.LBORINGSSL_external_toc


+ 3
- 0
util/fipstools/testdata/ppc64le-LoadToR0/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
@@ -23,6 +25,7 @@ foo:
ld 3, -8(1)
addi 1, 1, 288
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type bcm_loadtoc_bar, @function
bcm_loadtoc_bar:


+ 3
- 0
util/fipstools/testdata/ppc64le-Sample/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.file "foo.c"
.abiversion 2
@@ -415,6 +417,7 @@ exported_function:
.ident "GCC: (Ubuntu 4.9.2-10ubuntu13) 4.9.2"
.section .note.GNU-stack,"",@progbits
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.section ".toc", "aw"
.Lredirector_toc_fprintf:


+ 3
- 0
util/fipstools/testdata/ppc64le-Sample2/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.file "foo.c"
.abiversion 2
@@ -534,6 +536,7 @@ bss:
.ident "GCC: (Ubuntu 4.9.2-10ubuntu13) 4.9.2"
.section .note.GNU-stack,"",@progbits
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.section ".toc", "aw"
.Lredirector_toc___fprintf_chk:


+ 3
- 0
util/fipstools/testdata/ppc64le-TOCWithOffset/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
@@ -99,6 +101,7 @@ foo:
ld 3, -16(1)
addi 1, 1, 288
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type bcm_loadtoc__dot_Lfoo_local_target, @function
bcm_loadtoc__dot_Lfoo_local_target:


+ 3
- 0
util/fipstools/testdata/x86_64-BSS/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
movq %rax, %rax
@@ -41,6 +43,7 @@ z:

.quad 0
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type aes_128_ctr_generic_storage_bss_get, @function
aes_128_ctr_generic_storage_bss_get:


+ 3
- 0
util/fipstools/testdata/x86_64-Basic/out.s View File

@@ -1,4 +1,6 @@
.text
.file 2 "inserted_by_delocate.c"
.loc 2 1 0
BORINGSSL_bcm_text_start:
# Most instructions and lines should pass unaltered. This is made up of
# copy-and-pasted bits of compiler output and likely does not actually
@@ -51,6 +53,7 @@ foo:
.size foo, .-foo
.type foo, @function
.text
.loc 2 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
OPENSSL_ia32cap_get:


+ 3
- 0
util/fipstools/testdata/x86_64-GOTRewrite/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
@@ -148,6 +150,7 @@ foo:

.comm foobar,64,32
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type foobar_bss_get, @function
foobar_bss_get:


+ 3
- 0
util/fipstools/testdata/x86_64-LabelRewrite/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.type foo, @function
.globl foo
@@ -82,6 +84,7 @@ bar:
.quad .L2_BCM_1-.L1_BCM_1

.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type bcm_redirector_memcpy, @function
bcm_redirector_memcpy:


+ 3
- 0
util/fipstools/testdata/x86_64-Sections/out.s View File

@@ -1,4 +1,6 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
# .text stays in .text
.text
@@ -43,6 +45,7 @@ foo:
.byte 0x1
.long .L3
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
OPENSSL_ia32cap_get:


Loading…
Cancel
Save