This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[commit] PowerPC gas fixups on data
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: binutils at sourceware dot org
- Cc: amodra at gmail dot com
- Date: Wed, 14 Nov 2012 14:50:48 +0100 (CET)
- Subject: [commit] PowerPC gas fixups on data
Hello,
recently Alan Modra changed md_apply_fix to leave insn text fields zero
when applying a fixup that results in a relocation. However, for fixups
that apply to data fields, the assembler still modifies the segment text
(even though this is ignored later on when the linker applies the RelA
relocation).
For consistency (between insn and data relocs, with the behaviour of gas
on other RelA platforms like x86-64, and with other PowerPC assemblers),
we thought it would be preferable for gas to leave such fields zero as
well. The following patch implements this.
Tested on powerpc-linux and powerpc64-linux.
Approved off-line by Alan, applied to mainline.
Bye,
Ulrich
gas/ChangeLog:
* config/tc-ppc.c (md_apply_fix): Leave field zero when emitting
an ELF reloc on data as well.
gas/testsuite/ChangeLog:
* gas/ppc/astest.d: Update for fixup changes.
* gas/ppc/astest64.d: Likewise.
* gas/ppc/astest2.d: Likewise.
* gas/ppc/astest2_64.d: Likewise.
* gas/ppc/test1elf32.d: Likewise.
* gas/ppc/test1elf64.d: Likewise.
Index: gas/config/tc-ppc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ppc.c,v
retrieving revision 1.190
diff -u -p -r1.190 tc-ppc.c
--- gas/config/tc-ppc.c 6 Nov 2012 05:18:03 -0000 1.190
+++ gas/config/tc-ppc.c 14 Nov 2012 13:35:32 -0000
@@ -6620,6 +6620,9 @@ md_apply_fix (fixS *fixP, valueT *valP,
}
else
{
+ int size = 0;
+ offsetT fieldval = value;
+
/* Handle relocs in data. */
switch (fixP->fx_r_type)
{
@@ -6635,8 +6638,7 @@ md_apply_fix (fixS *fixP, valueT *valP,
case BFD_RELOC_32_PCREL:
case BFD_RELOC_RVA:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- value, 4);
+ size = 4;
break;
case BFD_RELOC_64:
@@ -6646,8 +6648,7 @@ md_apply_fix (fixS *fixP, valueT *valP,
/* fall through */
case BFD_RELOC_64_PCREL:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- value, 8);
+ size = 8;
break;
case BFD_RELOC_16:
@@ -6656,8 +6657,7 @@ md_apply_fix (fixS *fixP, valueT *valP,
/* fall through */
case BFD_RELOC_16_PCREL:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- value, 2);
+ size = 2;
break;
case BFD_RELOC_8:
@@ -6690,8 +6690,7 @@ md_apply_fix (fixS *fixP, valueT *valP,
fixP->fx_done = 1;
}
else
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- value, 1);
+ size = 1;
break;
case BFD_RELOC_VTABLE_INHERIT:
@@ -6711,52 +6710,51 @@ md_apply_fix (fixS *fixP, valueT *valP,
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
case BFD_RELOC_LO16_PCREL:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- value, 2);
+ size = 2;
break;
case BFD_RELOC_HI16:
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
case BFD_RELOC_HI16_PCREL:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HI (value), 2);
+ size = 2;
+ fieldval = PPC_HI (value);
break;
case BFD_RELOC_HI16_S:
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
case BFD_RELOC_HI16_S_PCREL:
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HA (value), 2);
+ size = 2;
+ fieldval = PPC_HA (value);
break;
case BFD_RELOC_PPC64_HIGHER:
if (fixP->fx_pcrel)
goto bad_pcrel;
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HIGHER (value), 2);
+ size = 2;
+ fieldval = PPC_HIGHER (value);
break;
case BFD_RELOC_PPC64_HIGHER_S:
if (fixP->fx_pcrel)
goto bad_pcrel;
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HIGHERA (value), 2);
+ size = 2;
+ fieldval = PPC_HIGHERA (value);
break;
case BFD_RELOC_PPC64_HIGHEST:
if (fixP->fx_pcrel)
goto bad_pcrel;
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HIGHEST (value), 2);
+ size = 2;
+ fieldval = PPC_HIGHEST (value);
break;
case BFD_RELOC_PPC64_HIGHEST_S:
if (fixP->fx_pcrel)
goto bad_pcrel;
- md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
- PPC_HIGHESTA (value), 2);
+ size = 2;
+ fieldval = PPC_HIGHESTA (value);
break;
case BFD_RELOC_PPC_DTPMOD:
@@ -6856,6 +6854,10 @@ md_apply_fix (fixS *fixP, valueT *valP,
fflush (stderr);
abort ();
}
+
+ if (size && APPLY_RELOC)
+ md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
+ fieldval, size);
}
#ifdef OBJ_ELF
Index: gas/testsuite/gas/ppc/astest.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/astest.d,v
retrieving revision 1.5
diff -u -p -r1.5 astest.d
--- gas/testsuite/gas/ppc/astest.d 29 Oct 2012 09:25:15 -0000 1.5
+++ gas/testsuite/gas/ppc/astest.d 14 Nov 2012 13:35:33 -0000
@@ -33,42 +33,28 @@ Disassembly of section \.text:
38: (48 00 00 00|00 00 00 48) b .*
38: R_PPC_LOCAL24PC a
3c: (4b ff ff d4|d4 ff ff 4b) b 10 <apfour>
- 40: (00 00 00 40|40 00 00 00) \.long 0x40
+ \.\.\.
40: R_PPC_ADDR32 \.text\+0x40
- 44: (00 00 00 4c|4c 00 00 00) \.long 0x4c
44: R_PPC_ADDR32 \.text\+0x4c
- 48: (00 00 00 00|00 00 00 00) \.long 0x0
48: R_PPC_REL32 x
- 4c: (00 00 00 04|04 00 00 00) \.long 0x4
4c: R_PPC_REL32 x\+0x4
- 50: (00 00 00 00|00 00 00 00) \.long 0x0
50: R_PPC_REL32 z
- 54: (00 00 00 04|04 00 00 00) \.long 0x4
54: R_PPC_REL32 \.data\+0x4
- 58: (00 00 00 00|00 00 00 00) \.long 0x0
58: R_PPC_ADDR32 x
- 5c: (00 00 00 04|04 00 00 00) \.long 0x4
5c: R_PPC_ADDR32 \.data\+0x4
- 60: (00 00 00 00|00 00 00 00) \.long 0x0
60: R_PPC_ADDR32 z
- 64: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
64: R_PPC_ADDR32 x-0x4
- 68: (00 00 00 00|00 00 00 00) \.long 0x0
68: R_PPC_ADDR32 \.data
- 6c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
6c: R_PPC_ADDR32 z-0x4
70: (ff ff ff 9c|9c ff ff ff) \.long 0xffffff9c
74: (ff ff ff 9c|9c ff ff ff) \.long 0xffffff9c
- 78: (00 00 00 00|00 00 00 00) \.long 0x0
+ \.\.\.
78: R_PPC_ADDR32 a
- 7c: (00 00 00 10|10 00 00 00) \.long 0x10
7c: R_PPC_ADDR32 \.text\+0x10
- 80: (00 00 00 10|10 00 00 00) \.long 0x10
80: R_PPC_ADDR32 \.text\+0x10
84: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
- 88: (00 00 00 12|12 00 00 00) \.long 0x12
+ \.\.\.
88: R_PPC_ADDR32 \.text\+0x12
- 8c: 00 00 00 00 \.long 0x0
Disassembly of section \.data:
0+0000000 <x>:
Index: gas/testsuite/gas/ppc/astest2.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/astest2.d,v
retrieving revision 1.7
diff -u -p -r1.7 astest2.d
--- gas/testsuite/gas/ppc/astest2.d 29 Oct 2012 09:25:15 -0000 1.7
+++ gas/testsuite/gas/ppc/astest2.d 14 Nov 2012 13:35:33 -0000
@@ -29,29 +29,18 @@ Disassembly of section \.text:
38: (48 00 00 00|00 00 00 48) b .*
38: R_PPC_LOCAL24PC a
3c: (48 00 00 40|40 00 00 48) b 7c <apfour>
- 40: (00 00 00 40|40 00 00 00) \.long 0x40
+ \.\.\.
40: R_PPC_ADDR32 \.text\+0x40
- 44: (00 00 00 4c|4c 00 00 00) \.long 0x4c
44: R_PPC_ADDR32 \.text\+0x4c
- 48: (00 00 00 00|00 00 00 00) \.long 0x0
48: R_PPC_REL32 x
- 4c: (00 00 00 04|04 00 00 00) \.long 0x4
4c: R_PPC_REL32 x\+0x4
- 50: (00 00 00 00|00 00 00 00) \.long 0x0
50: R_PPC_REL32 z
- 54: (00 00 00 04|04 00 00 00) \.long 0x4
54: R_PPC_REL32 \.data\+0x4
- 58: (00 00 00 00|00 00 00 00) \.long 0x0
58: R_PPC_ADDR32 x
- 5c: (00 00 00 04|04 00 00 00) \.long 0x4
5c: R_PPC_ADDR32 \.data\+0x4
- 60: (00 00 00 00|00 00 00 00) \.long 0x0
60: R_PPC_ADDR32 z
- 64: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
64: R_PPC_ADDR32 x-0x4
- 68: (00 00 00 00|00 00 00 00) \.long 0x0
68: R_PPC_ADDR32 \.data
- 6c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
6c: R_PPC_ADDR32 z-0x4
70: (00 00 00 08|08 00 00 00) \.long 0x8
74: (00 00 00 08|08 00 00 00) \.long 0x8
@@ -61,14 +50,12 @@ Disassembly of section \.text:
78: R_PPC_ADDR32 a
0+000007c <apfour>:
- 7c: (00 00 00 7c|7c 00 00 00) \.long 0x7c
+ \.\.\.
7c: R_PPC_ADDR32 \.text\+0x7c
- 80: (00 00 00 7c|7c 00 00 00) \.long 0x7c
80: R_PPC_ADDR32 \.text\+0x7c
84: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
- 88: (00 00 00 7e|7e 00 00 00) \.long 0x7e
+ \.\.\.
88: R_PPC_ADDR32 \.text\+0x7e
- 8c: (00 00 00 00|00 00 00 00) \.long 0x0
90: (60 00 00 00|00 00 00 60) nop
94: (40 a5 ff fc|fc ff a5 40) ble- cr1,90 <apfour\+0x14>
98: (41 a9 ff f8|f8 ff a9 41) bgt- cr2,90 <apfour\+0x14>
Index: gas/testsuite/gas/ppc/astest2_64.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/astest2_64.d,v
retrieving revision 1.5
diff -u -p -r1.5 astest2_64.d
--- gas/testsuite/gas/ppc/astest2_64.d 29 Oct 2012 09:25:15 -0000 1.5
+++ gas/testsuite/gas/ppc/astest2_64.d 14 Nov 2012 13:35:33 -0000
@@ -26,29 +26,18 @@ Disassembly of section \.text:
30: (48 00 00 0.|0. 00 00 48) b .*
30: R_PPC64_REL24 a\+0x4
34: (48 00 00 44|44 00 00 48) b 78 <apfour\+0x4>
- 38: (00 00 00 38|38 00 00 00) \.long 0x38
+ \.\.\.
38: R_PPC64_ADDR32 \.text\+0x38
- 3c: (00 00 00 44|44 00 00 00) \.long 0x44
3c: R_PPC64_ADDR32 \.text\+0x44
- 40: (00 00 00 00|00 00 00 00) \.long 0x0
40: R_PPC64_REL32 x
- 44: (00 00 00 04|04 00 00 00) \.long 0x4
44: R_PPC64_REL32 x\+0x4
- 48: (00 00 00 00|00 00 00 00) \.long 0x0
48: R_PPC64_REL32 z
- 4c: (00 00 00 04|04 00 00 00) \.long 0x4
4c: R_PPC64_REL32 \.data\+0x4
- 50: (00 00 00 00|00 00 00 00) \.long 0x0
50: R_PPC64_ADDR32 x
- 54: (00 00 00 04|04 00 00 00) \.long 0x4
54: R_PPC64_ADDR32 \.data\+0x4
- 58: (00 00 00 00|00 00 00 00) \.long 0x0
58: R_PPC64_ADDR32 z
- 5c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
5c: R_PPC64_ADDR32 x-0x4
- 60: (00 00 00 00|00 00 00 00) \.long 0x0
60: R_PPC64_ADDR32 \.data
- 64: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
64: R_PPC64_ADDR32 z-0x4
68: (00 00 00 08|08 00 00 00) \.long 0x8
6c: (00 00 00 08|08 00 00 00) \.long 0x8
@@ -58,14 +47,12 @@ Disassembly of section \.text:
70: R_PPC64_ADDR32 a
0000000000000074 <apfour>:
- 74: (00 00 00 74|74 00 00 00) \.long 0x74
+ \.\.\.
74: R_PPC64_ADDR32 \.text\+0x74
- 78: (00 00 00 74|74 00 00 00) \.long 0x74
78: R_PPC64_ADDR32 \.text\+0x74
7c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
- 80: (00 00 00 76|76 00 00 00) \.long 0x76
+ \.\.\.
80: R_PPC64_ADDR32 \.text\+0x76
- 84: (00 00 00 00|00 00 00 00) \.long 0x0
Disassembly of section \.data:
0000000000000000 <x>:
Index: gas/testsuite/gas/ppc/astest64.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/astest64.d,v
retrieving revision 1.5
diff -u -p -r1.5 astest64.d
--- gas/testsuite/gas/ppc/astest64.d 29 Oct 2012 09:25:15 -0000 1.5
+++ gas/testsuite/gas/ppc/astest64.d 14 Nov 2012 13:35:33 -0000
@@ -30,42 +30,28 @@ Disassembly of section \.text:
30: (48 00 00 0.|0. 00 00 48) b .*
30: R_PPC64_REL24 a\+0x4
34: (4b ff ff e0|e0 ff ff 4b) b 14 <apfour\+0x4>
- 38: (00 00 00 38|38 00 00 00) \.long 0x38
+ \.\.\.
38: R_PPC64_ADDR32 \.text\+0x38
- 3c: (00 00 00 44|44 00 00 00) \.long 0x44
3c: R_PPC64_ADDR32 \.text\+0x44
- 40: (00 00 00 00|00 00 00 00) \.long 0x0
40: R_PPC64_REL32 x
- 44: (00 00 00 04|04 00 00 00) \.long 0x4
44: R_PPC64_REL32 x\+0x4
- 48: (00 00 00 00|00 00 00 00) \.long 0x0
48: R_PPC64_REL32 z
- 4c: (00 00 00 04|04 00 00 00) \.long 0x4
4c: R_PPC64_REL32 \.data\+0x4
- 50: (00 00 00 00|00 00 00 00) \.long 0x0
50: R_PPC64_ADDR32 x
- 54: (00 00 00 04|04 00 00 00) \.long 0x4
54: R_PPC64_ADDR32 \.data\+0x4
- 58: (00 00 00 00|00 00 00 00) \.long 0x0
58: R_PPC64_ADDR32 z
- 5c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
5c: R_PPC64_ADDR32 x-0x4
- 60: (00 00 00 00|00 00 00 00) \.long 0x0
60: R_PPC64_ADDR32 \.data
- 64: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
64: R_PPC64_ADDR32 z-0x4
68: (ff ff ff a4|a4 ff ff ff) \.long 0xffffffa4
6c: (ff ff ff a4|a4 ff ff ff) \.long 0xffffffa4
- 70: (00 00 00 00|00 00 00 00) \.long 0x0
+ \.\.\.
70: R_PPC64_ADDR32 a
- 74: (00 00 00 10|10 00 00 00) \.long 0x10
74: R_PPC64_ADDR32 \.text\+0x10
- 78: (00 00 00 10|10 00 00 00) \.long 0x10
78: R_PPC64_ADDR32 \.text\+0x10
7c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
- 80: (00 00 00 12|12 00 00 00) \.long 0x12
+ \.\.\.
80: R_PPC64_ADDR32 \.text\+0x12
- 84: (00 00 00 00|00 00 00 00) \.long 0x0
Disassembly of section \.data:
0000000000000000 <x>:
Index: gas/testsuite/gas/ppc/test1elf32.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/test1elf32.d,v
retrieving revision 1.6
diff -u -p -r1.6 test1elf32.d
--- gas/testsuite/gas/ppc/test1elf32.d 29 Oct 2012 09:25:15 -0000 1.6
+++ gas/testsuite/gas/ppc/test1elf32.d 14 Nov 2012 13:35:33 -0000
@@ -74,17 +74,17 @@ Disassembly of section \.data:
4: (ca fe ba be|be ba fe ca) lfd f23,-17730\(r30\)
0+0008 <datpt>:
- 8: (00 98 96 80|80 96 98 00) \.long 0x989680
+ 8: 00 00 00 00 \.long 0x0
8: R_PPC_REL32 jk\+0x989680
0+000c <dat0>:
- c: (ff ff ff fc|fc ff ff ff) fnmsub f31,f31,f31,f31
+ c: 00 00 00 00 \.long 0x0
c: R_PPC_REL32 jk-0x4
0+0010 <dat1>:
- 10: (00 00 00 00|00 00 00 00) \.long 0x0
+ 10: 00 00 00 00 \.long 0x0
10: R_PPC_REL32 jk
0+0014 <dat2>:
- 14: (00 00 00 04|04 00 00 00) \.long 0x4
+ 14: 00 00 00 00 \.long 0x0
14: R_PPC_REL32 jk\+0x4
Index: gas/testsuite/gas/ppc/test1elf64.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/ppc/test1elf64.d,v
retrieving revision 1.7
diff -u -p -r1.7 test1elf64.d
--- gas/testsuite/gas/ppc/test1elf64.d 29 Oct 2012 09:25:15 -0000 1.7
+++ gas/testsuite/gas/ppc/test1elf64.d 14 Nov 2012 13:35:33 -0000
@@ -109,11 +109,11 @@ Disassembly of section \.data:
c: (ca fe ba be|00 00 00 00) .*
0000000000000010 <datpt>:
- 10: (00 98 96 80|80 96 98 00) .*
+ 10: 00 00 00 00 .*
10: R_PPC64_REL32 jk\+0x989680
0000000000000014 <dat0>:
- 14: (ff ff ff fc|fc ff ff ff) .*
+ 14: 00 00 00 00 .*
14: R_PPC64_REL32 jk-0x4
0000000000000018 <dat1>:
@@ -121,18 +121,16 @@ Disassembly of section \.data:
18: R_PPC64_REL32 jk
000000000000001c <dat2>:
- 1c: (00 00 00 04|04 00 00 00) .*
+ 1c: 00 00 00 00 .*
1c: R_PPC64_REL32 jk\+0x4
0000000000000020 <dat3>:
- 20: (00 00 00 00|08 00 00 00) .*
+ \.\.\.
20: R_PPC64_REL64 jk\+0x8
- 24: (00 00 00 08|00 00 00 00) .*
0000000000000028 <dat4>:
- 28: (00 00 00 00|10 00 00 00) .*
+ \.\.\.
28: R_PPC64_REL64 jk\+0x10
- 2c: (00 00 00 10|00 00 00 00) .*
Disassembly of section \.toc:
0000000000000000 <\.toc>:
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com