]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86/COFF: support section-index relocations in insn operands
authorJan Beulich <jbeulich@suse.com>
Mon, 2 Dec 2024 08:38:15 +0000 (09:38 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 2 Dec 2024 08:38:15 +0000 (09:38 +0100)
On the grounds of the principle put down near the bottom of [1], along
with image and section relative operations, let's also support as insn
operands what .secidx is for on the data side (of course like elsewhere
the reloc operator can then also be used for data generation, albeit a
small tweak to x86_cons() is needed for this to work).

[1] https://sourceware.org/pipermail/binutils/2024-November/137617.html

gas/config/tc-i386.c
gas/testsuite/gas/i386/secidx.d
gas/testsuite/gas/i386/secidx.s
gas/testsuite/gas/i386/x86-64-secidx.d [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-secidx.s [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64.exp

index c1c0d0fdd916d56b240f2bc3b8e5b48920e66b56..6720bc8e38b1f5118faa318e8872e6b4f9a8540a 100644 (file)
@@ -1411,6 +1411,9 @@ gotrel[] =
     { STRING_COMMA_LEN ("SECREL32"), { BFD_RELOC_32_SECREL,
                                       BFD_RELOC_32_SECREL },
     OPERAND_TYPE_IMM32_32S_DISP32, false },
+    { STRING_COMMA_LEN ("SECIDX16"), { BFD_RELOC_16_SECIDX,
+                                      BFD_RELOC_16_SECIDX },
+    { .bitfield = { .imm16 = 1, .disp16 = 1 } }, false },
     { STRING_COMMA_LEN ("RVA"), { BFD_RELOC_RVA,
                                       BFD_RELOC_RVA },
     OPERAND_TYPE_IMM32_32S_DISP32, false },
@@ -13133,7 +13136,11 @@ x86_cons (expressionS *exp, int size)
   expr_mode = expr_operator_none;
 
 #if defined (OBJ_ELF) || defined (TE_PE)
-  if (size == 4 || (object_64bit && size == 8))
+  if (size == 4
+# ifdef TE_PE
+      || (size == 2)
+# endif
+      || (object_64bit && size == 8))
     {
       /* Handle @GOTOFF and the like in an expression.  */
       char *save;
index 2db427bb908708cc8aee83dfbe959c332cb10fec..09ee013d23fd44f6efab12c88cc32340d6bef5f4 100644 (file)
@@ -3,6 +3,10 @@
 
 .*: +file format pe-i386
 
+RELOCATION RECORDS FOR \[\.text\]:
+OFFSET[        ]+TYPE[         ]+VALUE
+0+22 secidx            \.text
+
 RELOCATION RECORDS FOR \[\.data\]:
 OFFSET[        ]+TYPE[         ]+VALUE
 0+24 secidx            \.text
@@ -22,9 +26,14 @@ OFFSET[      ]+TYPE[         ]+VALUE
 0+72 secidx            ext36
 0+75 secidx            ext3f
 
+RELOCATION RECORDS FOR \[\.rdata\]:
+OFFSET[        ]+TYPE[         ]+VALUE
+0+24 secidx            \.rdata
+
 Contents of section \.text:
  0000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c  >>>><<<<>>>>><<<
  0010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c  >>>>>><<>>>>>>><
+ 0020 66b80000 .*
 Contents of section \.data:
  0000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c  >>>><<<<>>>>><<<
  0010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c  >>>>>><<>>>>>>><
@@ -37,4 +46,4 @@ Contents of section \.data:
 Contents of section \.rdata:
  0000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c  >>>><<<<>>>>><<<
  0010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c  >>>>>><<>>>>>>><
- 0020 3e3e3e3e 00000000 00000000 00000000  >>>>............
+ 0020 3e3e3e3e 24003c3c 3c3c0000 00000000  >>>>..<<<<......
index 7ac1d2c7036869191a1e21f6d11e6802ed5a74d8..2cc52a9844c79a86bf89f43f4c171b4d9fcce280 100644 (file)
@@ -9,6 +9,8 @@ pre16:  .ascii "<<"
        .ascii ">>>>>>>"
 pre1f: .ascii "<"
 
+       mov     $.text@secidx16, %ax
+
 .data
 
        .ascii ">>>>"
@@ -76,4 +78,8 @@ nex16:        .ascii "<<"
 nex1f: .ascii "<"
        .ascii ">>>>"
 
+       .word   .@secidx16
+
+       .ascii "<<<<"
+
        .p2align 4,0
diff --git a/gas/testsuite/gas/i386/x86-64-secidx.d b/gas/testsuite/gas/i386/x86-64-secidx.d
new file mode 100644 (file)
index 0000000..8affc0a
--- /dev/null
@@ -0,0 +1,25 @@
+#objdump: -rs
+#name: x86-64 imgrel (RVA) reloc
+
+.*: +file format pe-x86-64
+
+RELOCATION RECORDS FOR \[\.text\]:
+OFFSET[        ]+TYPE[         ]+VALUE
+0+02 IMAGE_REL_AMD64_SECTION  \.text
+0+07 IMAGE_REL_AMD64_SECTION  \.data
+0+0c IMAGE_REL_AMD64_SECTION  \.text
+0+11 IMAGE_REL_AMD64_SECTION  Xtrn
+
+RELOCATION RECORDS FOR \[\.data\]:
+OFFSET[        ]+TYPE[         ]+VALUE
+0+00 IMAGE_REL_AMD64_SECTION  \.text
+0+02 IMAGE_REL_AMD64_SECTION  \.data
+0+04 IMAGE_REL_AMD64_SECTION  \.data
+0+06 IMAGE_REL_AMD64_SECTION  Xtrn
+
+Contents of section \.text:
+ 0000 66b90000 6681c100 006681e9 09006681  .*
+ 0010 f10000.*
+
+Contents of section \.data:
+ 0000 00000000 04000000 00000000 00000000  .*
diff --git a/gas/testsuite/gas/i386/x86-64-secidx.s b/gas/testsuite/gas/i386/x86-64-secidx.s
new file mode 100644 (file)
index 0000000..d2d8ef0
--- /dev/null
@@ -0,0 +1,13 @@
+       .text
+Text:
+       mov     $Text@secidx16, %cx
+       add     $Data@secidx16, %cx
+       sub     $.@secidx16, %cx
+       xor     $Xtrn@secidx16, %cx
+
+       .data
+Data:
+       .word   Text@secidx16
+       .word   Data@secidx16
+       .word   .@secidx16
+       .word   Xtrn@secidx16
index cbeef6ea223219b0ed8c49679c3fa75a1ec03b9b..e59daec551499cafc60d3301864b7d527fb7c04f 100644 (file)
@@ -60,6 +60,7 @@ if { ![istarget "*-*-*cygwin*"]
 } else {
     run_dump_test "x86-64-w64-pcrel"
     run_dump_test "x86-64-imgrel"
+    run_dump_test "x86-64-secidx"
 }
 run_list_test "pcrel64" "-al"
 run_dump_test "x86-64-rip"