[llvm] [llvm-objcopy] Support SREC output format (PR #75874)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 01:06:01 PST 2024


================
@@ -45,26 +29,164 @@
 # CHECK-NEXT: S30A8000100000010203045B
 # CHECK-NEXT: S70500000000FA
 
-# PADDR: S00400002DCE
-# PADDR-NEXT: S214100000000102030405060708090A0B0C0D0E0F63
-# PADDR-NEXT: S20910001010111213147C
-# PADDR-NEXT: S20F10001830313233343536373839407B
-# PADDR-NEXT: S20810002840414243B9
-# PADDR-NEXT: S20F100030505152535455565758596003
-# PADDR-NEXT: S20720FFF8000000E1
-# PADDR-NEXT: S804100000EB
+# ENTRY: S00400002DCE
+# ENTRY-NEXT: S705F00000000A
+
+# BAD_START: entry point address 0xf00000000 overflows 32 bits
+
+# BAD_EXTENDED_START: entry point address 0xffffffff0f000000 overflows 32 bits
 
-# BAD-ADDR: Section '.text1' address range [0xfffffff8, 0x100000000] is not 32 bit
-# BAD-ADDR2: Section '.text2' address range [0xffffffff0, 0xffffffff4] is not 32 bit
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_EXEC
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .data1
+# Records for this section should come last.
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC ]
+    Content:         "11111111111111111111"
+    Address:         0xEFFFFF
+  - Name:            .data2
+# This section overlaps 24-bit address boundary, so we expect
+# its record type to be S3.
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC ]
+    Content:         "3031323334353637383940"
+    Address:         0xFFFFF8
+# Sign-extended addresses are OK.
+  - Name:            .data3
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC ]
+    Address:         0xFFFFFFFF80001000
+    Content:         "0001020304"
+  - Name:            .text
+# This section's contents exceeds default line length of 16 bytes
+# so we expect two lines created for it. Records for this section
+# should appear before records for the previous section.
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC ]
+    Address:         0x1000
+    Content:         "000102030405060708090A0B0C0D0E0F1011121314"
+  - Name:            .bss
+# NOBITS sections are not written.
+    Type:            SHT_NOBITS
+    Flags:           [ SHF_ALLOC ]
+    Address:         0x10100
+    Size:            0x1000
+  - Name:            .dummy
+# Non-allocatable sections are not written.
+    Type:            SHT_PROGBITS
+    Flags:           [ ]
+    Address:         0x20FFF8
+    Size:            65536
+
+## Check that section address range overlapping 32 bit range
+## triggers an error
+# RUN: yaml2obj %s --docnum=2 -o %t.err
+# RUN: not llvm-objcopy -O srec --only-section=.text1 %t.err - 2>&1 \
+#   RUN: | FileCheck %s --check-prefix=BAD-ADDR
+# RUN: not llvm-objcopy -O srec --only-section=.text2 %t.err - 2>&1 \
+#   RUN: | FileCheck %s --check-prefix=BAD-ADDR2
+
+## Check that zero length section is not written
+# RUN: llvm-objcopy -O srec --only-section=.text %t.err - \
+#   RUN:| FileCheck %s --check-prefix=ZERO_SIZE_SEC
+
+# BAD-ADDR: section '.text1' address range [0xfffffff8, 0x100000000] is not 32 bit
+# BAD-ADDR2: section '.text2' address range [0xffffffff0, 0xffffffff4] is not 32 bit
 
 # there should be no records besides header and terminator
 # ZERO_SIZE_SEC-NOT: {{S[1-8]}}
----------------
jh7370 wrote:

This just means that the test will fail if the pattern appears before the first positive check, which I'm guessing isn't what you meant? If you want to have it check in between every pattern you do check for, use `--implicit-check-not=<pattern>` on the FileCheck command-line. You could even check that the file is completely checked for by using `--implicit-check-not={{.}}`.

https://github.com/llvm/llvm-project/pull/75874


More information about the llvm-commits mailing list