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

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 02:45:28 PDT 2024


================
@@ -1,84 +1,67 @@
-# 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
-# RUN: llvm-objcopy --change-section-address .anotherone-0x30 --change-section-address .anotherone+0x20 %ti %to
-# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-USE-LAST
-
-# Check unused option
-# RUN: llvm-objcopy --change-section-address .anotherone=0x455 --change-section-address *+0x20 %ti %to
-# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-NOTSUPERSET-SET
-
-# Check partial overlap (.anotherone overlaps)
-# RUN: llvm-objcopy --change-section-address *+0x20 --change-section-address .anotherone=0x455 %ti %to
-# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-SUPERSET-SET
-
-# Check more complex partial overlap (P1: .anotherone, .text2, P2: .text1, text2) (.text2 overlaps)
-# RUN: llvm-objcopy --regex  --change-section-address  ".(text2|anotherone)+0x20" --change-section-address .text.*+0x30  %ti %to
-# RUN: llvm-readelf --section-headers %to | FileCheck %s --check-prefix=CHECK-PARTIAL-OVERLAP
+## This test tests the behavior of --change-section-address option.
+
+# RUN: yaml2obj -DTYPE=REL %s -o %ti1
+
+## Basic check that the option processes wildcards and changes the address as expected.
+# RUN: llvm-objcopy --change-section-address *+0x20 %ti1 %to1
+# RUN: llvm-readelf --section-headers %to1 | FileCheck %s --check-prefix=CHECK-ADD-ALL
+
+## Check that --change-section-address alias --adjust-section-vma produces the same output as the test above.
+# RUN: llvm-objcopy --adjust-section-vma *+0x20 %ti1 %to2
+# RUN: llvm-readelf --section-headers %to2 | FileCheck %s --check-prefix=CHECK-ADD-ALL
+
+## Check that negative adjustment reduces the address by the specified value.
+# RUN: llvm-objcopy --change-section-address .anotherone-0x30 %ti1 %to3
+# RUN: llvm-readelf --section-headers %to3 | FileCheck %s --check-prefix=CHECK-SUB-SECTION
+
+## Check that a wildcard pattern works and only the specified sections are updated.
+# RUN: llvm-objcopy --change-section-address .text*+0x20 %ti1 %to4
+# RUN: llvm-readelf --section-headers %to4 | FileCheck %s --check-prefix=CHECK-ADD-PATTERN
+
+## Check that regex pattern can be used with --change-section-address.
+# RUN: llvm-objcopy --regex --change-section-address .text.+0x20 %ti1 %to5
+# RUN: llvm-readelf --section-headers %to5 | FileCheck %s --check-prefix=CHECK-ADD-PATTERN
+
+## Check that a section address can be set to a specific value.
+# RUN: llvm-objcopy --change-section-address .text*=0x10 %ti1 %to6
+# RUN: llvm-readelf --section-headers %to6 | FileCheck %s --check-prefix=CHECK-SET-PATTERN
+
+## Check setting that a section address can be set to the maximum possible value (UINT64_MAX).
+# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti1 %to7
+# RUN: llvm-readelf --section-headers %to7 | FileCheck %s --check-prefix=CHECK-MAX
+
+## Check that a section address can be adjusted to the maximum possible value (UINT64_MAX).
+# RUN: llvm-objcopy --change-section-address .text2+0xfffffffffffffdff %ti1 %to8
+# RUN: llvm-readelf --section-headers %to8 | FileCheck %s --check-prefix=CHECK-MAX
+
+## Check that the section address can be adjusted to the minimum possible value (0).
+# RUN: llvm-objcopy --change-section-address .text2-0x200 %ti1 %to9
+# RUN: llvm-readelf --section-headers %to9 | FileCheck %s --check-prefix=CHECK-ZERO
+
+## Check that a section address can be adjusted by a maximum possible negative offset (UINT64_MIN).
+# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti1 %to10
+# RUN: llvm-objcopy --change-section-address .text2-0xffffffffffffffff %to10 %to11
----------------
jh7370 wrote:

I wonder if we should have a "+0xffffffffffffffff" case too? What do you think?

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


More information about the llvm-commits mailing list