[llvm] [llvm-objcopy] Add --change-section-address (PR #98664)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 02:14:26 PDT 2024


================
@@ -0,0 +1,211 @@
+# Tests behavior of --change-section-address option
+# --------------------------------------------------
+# yaml2obj generates an object file %ti that looks like this:
+#
+# llvm-readelf --section-headers %ti
+# Section Headers:
+#   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
+#   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
+#   [ 1] .text1            PROGBITS        0000000000000100 000040 000100 00      0   0  0
+#   [ 2] .text2            PROGBITS        0000000000000200 000140 000100 00      0   0  0
+#   [ 3] .anotherone       PROGBITS        0000000000000300 000240 000100 00      0   0  0
+#   [ 4] =a-b+c++d         PROGBITS        0000000000000400 000340 000100 00      0   0  0
+#   [ 5] .strtab           STRTAB          0000000000000000 000440 000001 00      0   0  1
+#   [ 6] .shstrtab         STRTAB          0000000000000000 000441 000037 00      0   0  1
+#
+# Various changes are applied to this file using llvm-objcopy --change-section-address and
+# results are checked for expected address values, or errors.
+#
+
+# RUN: yaml2obj -DTYPE=REL %s -o %ti
+
+# Basic check that the option processes wildcards and changes the address as expected
+# RUN: llvm-objcopy --change-section-address *+0x20 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ADD-ALL
+
+# Check --change-section-address alias --adjust-section-vma
+# RUN: llvm-objcopy --adjust-section-vma *+0x20 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ADD-ALL
+
+# Check negative adjustment
+# RUN: llvm-objcopy --change-section-address .anotherone-0x30 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-SUB-SECTION
+
+# Check wildcard that does not change all sections
+# RUN: llvm-objcopy --change-section-address .text*+0x20 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ADD-PATTERN
+
+# Check regex
+# RUN: llvm-objcopy --regex --change-section-address .text.+0x20 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ADD-PATTERN
+
+# Check setting the address to a specific value
+# RUN: llvm-objcopy --change-section-address .text*=0x10 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-SET-PATTERN
+
+# Check adjustment to max possible value (UINT64_MAX)
+# RUN: llvm-objcopy --change-section-address .text2+0xfffffffffffffdff %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-MAX
+
+# Check adjustment to min possible value (0)
+# RUN: llvm-objcopy --change-section-address .text2-0x200 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ZERO
+
+# Check setting to max possible value (UINT64_MAX)
+# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-MAX
+
+# Check maximum negative adjustment
+# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti %to1
+# RUN: llvm-objcopy --change-section-address .text2-0xffffffffffffffff %to1 %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-ZERO
+
+# Check two independent changes
+# RUN: llvm-objcopy --change-section-address .text1=0x110 --change-section-address .text2=0x210 %ti %to
+# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-INDEPENDENT
+
+# check two overlapping changes
----------------
jh7370 wrote:

```suggestion
# Check two overlapping changes
```

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


More information about the llvm-commits mailing list