From f61870199f1bdfe3182e493231e60ea7243edbcb Mon Sep 17 00:00:00 2001 From: Sean McGrail <549813+skmcgrail@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:22:45 -0800 Subject: [PATCH] Fix Clang-6 FIPS static build issue (#1424) 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. --- util/fipstools/delocate/delocate.go | 17 ----------------- .../delocate/testdata/aarch64-Basic/out.s | 3 --- .../testdata/generic-FileDirectives/out.s | 3 --- .../delocate/testdata/generic-Includes/out.s | 3 --- .../delocate/testdata/ppc64le-GlobalEntry/out.s | 3 --- .../delocate/testdata/ppc64le-LoadToR0/out.s | 3 --- .../delocate/testdata/ppc64le-Sample/out.s | 3 --- .../delocate/testdata/ppc64le-Sample2/out.s | 3 --- .../testdata/ppc64le-TOCWithOffset/out.s | 3 --- .../delocate/testdata/x86_64-BSS/out.s | 3 --- .../delocate/testdata/x86_64-Basic/out.s | 3 --- .../delocate/testdata/x86_64-GOTRewrite/out.s | 3 --- .../delocate/testdata/x86_64-LabelRewrite/out.s | 3 --- .../delocate/testdata/x86_64-LargeMemory/out.s | 3 --- .../delocate/testdata/x86_64-Sections/out.s | 3 --- .../delocate/testdata/x86_64-ThreeArg/out.s | 3 --- 16 files changed, 62 deletions(-) diff --git a/util/fipstools/delocate/delocate.go b/util/fipstools/delocate/delocate.go index 6c63c6cc26..8dca9222a7 100644 --- a/util/fipstools/delocate/delocate.go +++ b/util/fipstools/delocate/delocate.go @@ -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{}{} @@ -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) } @@ -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 @@ -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")) diff --git a/util/fipstools/delocate/testdata/aarch64-Basic/out.s b/util/fipstools/delocate/testdata/aarch64-Basic/out.s index c947525e18..a23cbddbde 100644 --- a/util/fipstools/delocate/testdata/aarch64-Basic/out.s +++ b/util/fipstools/delocate/testdata/aarch64-Basic/out.s @@ -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: @@ -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: diff --git a/util/fipstools/delocate/testdata/generic-FileDirectives/out.s b/util/fipstools/delocate/testdata/generic-FileDirectives/out.s index 80d7d526c2..5ab8fc7ef1 100644 --- a/util/fipstools/delocate/testdata/generic-FileDirectives/out.s +++ b/util/fipstools/delocate/testdata/generic-FileDirectives/out.s @@ -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" @@ -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 diff --git a/util/fipstools/delocate/testdata/generic-Includes/out.s b/util/fipstools/delocate/testdata/generic-Includes/out.s index c835dfe734..8c4e139736 100644 --- a/util/fipstools/delocate/testdata/generic-Includes/out.s +++ b/util/fipstools/delocate/testdata/generic-Includes/out.s @@ -1,8 +1,6 @@ #include #include .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" @@ -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 diff --git a/util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s b/util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s index d75e2c7f1d..e034bab53a 100644 --- a/util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s +++ b/util/fipstools/delocate/testdata/ppc64le-GlobalEntry/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text .Lfoo_local_target: @@ -21,7 +19,6 @@ foo: bl .text -.loc 1 2 0 BORINGSSL_bcm_text_end: .LBORINGSSL_external_toc: .quad .TOC.-.LBORINGSSL_external_toc diff --git a/util/fipstools/delocate/testdata/ppc64le-LoadToR0/out.s b/util/fipstools/delocate/testdata/ppc64le-LoadToR0/out.s index dad7603ab0..8ef4f0ba80 100644 --- a/util/fipstools/delocate/testdata/ppc64le-LoadToR0/out.s +++ b/util/fipstools/delocate/testdata/ppc64le-LoadToR0/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text .Lfoo_local_target: @@ -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: diff --git a/util/fipstools/delocate/testdata/ppc64le-Sample/out.s b/util/fipstools/delocate/testdata/ppc64le-Sample/out.s index 71ad6c20b3..8e0fa899b8 100644 --- a/util/fipstools/delocate/testdata/ppc64le-Sample/out.s +++ b/util/fipstools/delocate/testdata/ppc64le-Sample/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .file "foo.c" .abiversion 2 @@ -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: diff --git a/util/fipstools/delocate/testdata/ppc64le-Sample2/out.s b/util/fipstools/delocate/testdata/ppc64le-Sample2/out.s index e24f53ec45..b2577a112a 100644 --- a/util/fipstools/delocate/testdata/ppc64le-Sample2/out.s +++ b/util/fipstools/delocate/testdata/ppc64le-Sample2/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .file "foo.c" .abiversion 2 @@ -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: diff --git a/util/fipstools/delocate/testdata/ppc64le-TOCWithOffset/out.s b/util/fipstools/delocate/testdata/ppc64le-TOCWithOffset/out.s index fc55ef2073..3c5abc4969 100644 --- a/util/fipstools/delocate/testdata/ppc64le-TOCWithOffset/out.s +++ b/util/fipstools/delocate/testdata/ppc64le-TOCWithOffset/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text .Lfoo_local_target: @@ -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: diff --git a/util/fipstools/delocate/testdata/x86_64-BSS/out.s b/util/fipstools/delocate/testdata/x86_64-BSS/out.s index fd64b8f8fc..65b90f2f48 100644 --- a/util/fipstools/delocate/testdata/x86_64-BSS/out.s +++ b/util/fipstools/delocate/testdata/x86_64-BSS/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text movq %rax, %rax @@ -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: diff --git a/util/fipstools/delocate/testdata/x86_64-Basic/out.s b/util/fipstools/delocate/testdata/x86_64-Basic/out.s index af5eb89ff3..7c8f91c701 100644 --- a/util/fipstools/delocate/testdata/x86_64-Basic/out.s +++ b/util/fipstools/delocate/testdata/x86_64-Basic/out.s @@ -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 @@ -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 diff --git a/util/fipstools/delocate/testdata/x86_64-GOTRewrite/out.s b/util/fipstools/delocate/testdata/x86_64-GOTRewrite/out.s index 2ee6e50819..62afa18da5 100644 --- a/util/fipstools/delocate/testdata/x86_64-GOTRewrite/out.s +++ b/util/fipstools/delocate/testdata/x86_64-GOTRewrite/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text .Lfoo_local_target: @@ -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: diff --git a/util/fipstools/delocate/testdata/x86_64-LabelRewrite/out.s b/util/fipstools/delocate/testdata/x86_64-LabelRewrite/out.s index 10e40481b7..219052d641 100644 --- a/util/fipstools/delocate/testdata/x86_64-LabelRewrite/out.s +++ b/util/fipstools/delocate/testdata/x86_64-LabelRewrite/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .type foo, @function .globl foo @@ -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: diff --git a/util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s b/util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s index c460c57023..badab8276a 100644 --- a/util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s +++ b/util/fipstools/delocate/testdata/x86_64-LargeMemory/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .text @@ -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 diff --git a/util/fipstools/delocate/testdata/x86_64-Sections/out.s b/util/fipstools/delocate/testdata/x86_64-Sections/out.s index d107e30ebf..1add337e9f 100644 --- a/util/fipstools/delocate/testdata/x86_64-Sections/out.s +++ b/util/fipstools/delocate/testdata/x86_64-Sections/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: # .text stays in .text .text @@ -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 diff --git a/util/fipstools/delocate/testdata/x86_64-ThreeArg/out.s b/util/fipstools/delocate/testdata/x86_64-ThreeArg/out.s index 79cdbe60a5..377325dc6b 100644 --- a/util/fipstools/delocate/testdata/x86_64-ThreeArg/out.s +++ b/util/fipstools/delocate/testdata/x86_64-ThreeArg/out.s @@ -1,6 +1,4 @@ .text -.file 1 "inserted_by_delocate.c" -.loc 1 1 0 BORINGSSL_bcm_text_start: .type foo, @function .globl foo @@ -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