[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:27 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
----------------
jh7370 wrote:

We tend to use different output file names for each of the individual test cases, as it allows for better inspection of individual results, should it be necessary.

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


More information about the llvm-commits mailing list