Skip to content

Commit

Permalink
Fix Clang-6 FIPS static build issue (#1424)
Browse files Browse the repository at this point in the history
Clang-6 exhibits a behavior where a filno declaration in a `.file`
directive causes it to assume that all file numbers prior to it are
declared. This cause errors when later directives define lower numbered
filno's.

This only occurs because delocator computes the next largest fileno and
injects `.file`/`.loc` directives about the `BORINGSSL_bcm_text_start` and
`BORINGSSL_bcm_text_end` symbols. These aren't actually required to have
working debugging, so opting to remove this all together.
  • Loading branch information
skmcgrail authored Feb 22, 2024
1 parent c8d82c7 commit f618701
Show file tree
Hide file tree
Showing 16 changed files with 0 additions and 62 deletions.
17 changes: 0 additions & 17 deletions util/fipstools/delocate/delocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1776,10 +1776,6 @@ func transform(w stringWriter, includes []string, inputs []inputFile) error {
// maxObservedFileNumber contains the largest seen file number in a
// .file directive. Zero is not a valid number.
maxObservedFileNumber := 0
// fileDirectivesContainMD5 is true if the compiler is outputting MD5
// checksums in .file directives. If it does so, then this script needs
// to match that behaviour otherwise warnings result.
fileDirectivesContainMD5 := false

// OPENSSL_ia32cap_get will be synthesized by this script.
symbols["OPENSSL_ia32cap_get"] = struct{}{}
Expand Down Expand Up @@ -1847,12 +1843,6 @@ func transform(w stringWriter, includes []string, inputs []inputFile) error {
if fileNo > maxObservedFileNumber {
maxObservedFileNumber = fileNo
}

for _, token := range parts[2:] {
if token == "md5" {
fileDirectivesContainMD5 = true
}
}
}, ruleStatement, ruleLocationDirective)
}

Expand Down Expand Up @@ -1882,12 +1872,6 @@ func transform(w stringWriter, includes []string, inputs []inputFile) error {
}

w.WriteString(".text\n")
var fileTrailing string
if fileDirectivesContainMD5 {
fileTrailing = " md5 0x00000000000000000000000000000000"
}
w.WriteString(fmt.Sprintf(".file %d \"inserted_by_delocate.c\"%s\n", maxObservedFileNumber+1, fileTrailing))
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
// from a redirector function. For this to work, need to add the markers
Expand All @@ -1904,7 +1888,6 @@ func transform(w stringWriter, includes []string, inputs []inputFile) error {
}

w.WriteString(".text\n")
w.WriteString(fmt.Sprintf(".loc %d 2 0\n", maxObservedFileNumber+1))
if d.processor == aarch64 {
w.WriteString(fmt.Sprintf(".global BORINGSSL_bcm_text_end\n"))
w.WriteString(fmt.Sprintf(".type BORINGSSL_bcm_text_end, @function\n"))
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/aarch64-Basic/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
.global BORINGSSL_bcm_text_start
.type BORINGSSL_bcm_text_start, @function
BORINGSSL_bcm_text_start:
Expand Down Expand Up @@ -171,7 +169,6 @@ bss_symbol:
.word 0
.size bss_symbol, 4
.text
.loc 1 2 0
.global BORINGSSL_bcm_text_end
.type BORINGSSL_bcm_text_end, @function
BORINGSSL_bcm_text_end:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/generic-FileDirectives/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1002 "inserted_by_delocate.c" md5 0x00000000000000000000000000000000
.loc 1002 1 0
BORINGSSL_bcm_text_start:
.file 10 "some/path/file.c" "file.c"
.file 1000 "some/path/file2.c" "file2.c"
Expand All @@ -9,7 +7,6 @@ BORINGSSL_bcm_text_start:
# An instruction is needed to satisfy the architecture auto-detection.
movq %rax, %rbx
.text
.loc 1002 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/generic-Includes/out.s
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <openssl/foo.h>
#include <openssl/bar.h>
.text
.file 1002 "inserted_by_delocate.c" md5 0x00000000000000000000000000000000
.loc 1002 1 0
BORINGSSL_bcm_text_start:
.file 10 "some/path/file.c" "file.c"
.file 1000 "some/path/file2.c" "file2.c"
Expand All @@ -11,7 +9,6 @@ BORINGSSL_bcm_text_start:
# An instruction is needed to satisfy the architecture auto-detection.
movq %rax, %rbx
.text
.loc 1002 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
Expand All @@ -21,7 +19,6 @@ foo:

bl
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.LBORINGSSL_external_toc:
.quad .TOC.-.LBORINGSSL_external_toc
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/ppc64le-LoadToR0/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
Expand All @@ -25,7 +23,6 @@ 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:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/ppc64le-Sample/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.file "foo.c"
.abiversion 2
Expand Down Expand Up @@ -417,7 +415,6 @@ 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:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/ppc64le-Sample2/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.file "foo.c"
.abiversion 2
Expand Down Expand Up @@ -536,7 +534,6 @@ 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:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/ppc64le-TOCWithOffset/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
Expand Down Expand Up @@ -101,7 +99,6 @@ 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:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-BSS/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
movq %rax, %rax
Expand Down Expand Up @@ -43,7 +41,6 @@ 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:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-Basic/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.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
Expand Down Expand Up @@ -59,7 +57,6 @@ foo:
.type foo, @function
.uleb128 .foo-1-.bar
.text
.loc 2 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-GOTRewrite/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text
.Lfoo_local_target:
Expand Down Expand Up @@ -258,7 +256,6 @@ LOPENSSL_ia32cap_P_rbx3_return:

.comm foobar,64,32
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type foobar_bss_get, @function
foobar_bss_get:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-LabelRewrite/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.type foo, @function
.globl foo
Expand Down Expand Up @@ -96,7 +94,6 @@ bar:
.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
BORINGSSL_bcm_text_end:
.type .Lbcm_redirector_memcpy, @function
.Lbcm_redirector_memcpy:
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.text

Expand Down Expand Up @@ -39,7 +37,6 @@ BORINGSSL_bcm_text_start:
# jmpq *%rax

.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-Sections/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
# .text stays in .text
.text
Expand Down Expand Up @@ -45,7 +43,6 @@ foo:
.byte 0x1
.long .L3
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down
3 changes: 0 additions & 3 deletions util/fipstools/delocate/testdata/x86_64-ThreeArg/out.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.text
.file 1 "inserted_by_delocate.c"
.loc 1 1 0
BORINGSSL_bcm_text_start:
.type foo, @function
.globl foo
Expand Down Expand Up @@ -32,7 +30,6 @@ foo:
kBoringSSLRSASqrtTwo:
.quad -2404814165548301886 # 0xdea06241f7aa81c2
.text
.loc 1 2 0
BORINGSSL_bcm_text_end:
.type OPENSSL_ia32cap_get, @function
.globl OPENSSL_ia32cap_get
Expand Down

0 comments on commit f618701

Please sign in to comment.