gas:
authorNick Clifton <nickc@redhat.com>
Tue, 13 Oct 2009 08:55:31 +0000 (08:55 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 13 Oct 2009 08:55:31 +0000 (08:55 +0000)
2009-10-07  Vincent Riviere  <vincent.riviere@freesbee.fr>

        PR gas/3041
        * config/tc-m68k.c (tc_gen_reloc): Fix addend for relocations
        located in data section an referencing a weak symbol.

gas/testsuite:

2009-10-07  Vincent Riviere  <vincent.riviere@freesbee.fr>

        PR gas/3041
        * gas/m68k/all.exp: Added "p3041data".
        * gas/m68k/p3041.d, gas/m68k/p3041.s: Added tests of weak references
        from text section to all possible sections.
        * gas/m68k/p3041data.d, gas/m68k/p3041data.s: New test. Check weak
        references from data section.

gas/ChangeLog
gas/config/tc-m68k.c
gas/testsuite/ChangeLog
gas/testsuite/gas/m68k/all.exp
gas/testsuite/gas/m68k/p3041.d
gas/testsuite/gas/m68k/p3041.s
gas/testsuite/gas/m68k/p3041data.d [new file with mode: 0644]
gas/testsuite/gas/m68k/p3041data.s [new file with mode: 0644]

index d77f274af5c7d4c53afc21353e8211ac1f5c58ba..ac3953d7b275134f61bfb8878ac14b7ff81b8d87 100644 (file)
@@ -1,3 +1,9 @@
+2009-10-013  Vincent Riviere  <vincent.riviere@freesbee.fr>    
+
+       PR gas/3041
+       * config/tc-m68k.c (tc_gen_reloc): Fix addend for relocations
+       located in data section an referencing a weak symbol.
+
 2009-10-07  Nathan Sidwell  <nathan@codesourcery.com>
 
        * config/tc-arm.c (mapping_state, mapping_state_2): Make dummy
index 7bb6828260a2e8ca7755eeeffa98a63cc3889bd1..9616ba560ce671d6a5092ce96915917c5ebd3439 100644 (file)
@@ -1326,10 +1326,29 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
           && fixp->fx_addsy
           && S_IS_WEAK (fixp->fx_addsy)
           && ! bfd_is_und_section (S_GET_SEGMENT (fixp->fx_addsy)))
-    /* PR gas/3041 Adjust addend in order to force bfd_install_relocation()
-       to put the symbol offset into frags referencing a weak symbol.  */
-    reloc->addend = fixp->fx_addnumber
-                   - (S_GET_VALUE (fixp->fx_addsy) * 2);
+    {
+      /* PR gas/3041 References to weak symbols must be treated as extern
+        in order to be overridable by the linker, even if they are defined
+        in the same object file. So the original addend must be written
+        "as is" into the output section without further processing.
+        The addend value must be hacked here in order to force
+        bfd_install_relocation() to write the original value into the
+        output section.
+        1) MD_APPLY_SYM_VALUE() is set to 1 for m68k/a.out, so the symbol
+        value has already been added to the addend in fixup_segment(). We
+        have to remove it.
+        2) bfd_install_relocation() will incorrectly treat this symbol as
+        resolved, so it will write the symbol value plus its addend and
+        section VMA. As a workaround we can tweak the addend value here in
+        order to get the original value in the section after the call to
+        bfd_install_relocation().  */
+      reloc->addend = fixp->fx_addnumber
+                     /* Fix because of MD_APPLY_SYM_VALUE() */
+                     - S_GET_VALUE (fixp->fx_addsy)
+                     /* Fix for bfd_install_relocation() */
+                     - (S_GET_VALUE (fixp->fx_addsy)
+                        + S_GET_SEGMENT (fixp->fx_addsy)->vma);
+    }
   else
     reloc->addend = 0;
 #else
index a7cadf08b50357c7ee6e8aa81291459e6e70ace8..4a093bfd4600ada30bbb3753cb66b6320f7208d0 100644 (file)
@@ -1,3 +1,12 @@
+2009-10-13  Vincent Riviere  <vincent.riviere@freesbee.fr>     
+
+       PR gas/3041
+       * gas/m68k/all.exp: Added "p3041data".
+       * gas/m68k/p3041.d, gas/m68k/p3041.s: Added tests of weak references
+       from text section to all possible sections.
+       * gas/m68k/p3041data.d, gas/m68k/p3041data.s: New test. Check weak
+       references from data section.
+
 2009-10-08  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/10704
index 9cb9c2c0fcb69fe4c683ee0861ef524ca3d670cc..4a935611ec28372270f25c908d0ff4161bac913a 100644 (file)
@@ -71,6 +71,7 @@ if { [istarget m68*-*-*] || [istarget fido*-*-*] } then {
 
     if { [istarget *-*-netbsd] } then {
       run_dump_test p3041
+      run_dump_test p3041data
     }
 
     set testname "68000 operands"
index b4a41c4a01eeecf9cca6ea44085b20b72bae435a..f05648edf783164adc2d9ccbda6358bca5a61b6b 100644 (file)
@@ -1,15 +1,36 @@
 #name: PR 3041
-#objdump: -dr
+#objdump: -tdr
 
 .*:     file format .*
 
-Disassembly of section .text:
+SYMBOL TABLE:
+00000036  w      \.text 0000 00 0f mytext
+0000003e  w      \.data 0000 00 10 mydata
+0000004a  w      \.bss  0000 00 11 mybss
 
-0+ <.*>:
-   0:  4ef9 0000 0002 [        ]+jmp 2 <mylabel-0x6>
-                       2: .*   mylabel
-   6:  4e71 [  ]+nop
+Disassembly of section \.text:
 
-0+8 <mylabel>:
-   8:  4e71 [  ]+nop
-   a:  4e71 [  ]+nop
+00000000 <.*>:
+   0:  41f9 0000 0000  lea 0 <.*>,%a0
+                       2: 32   mytext
+   6:  41f9 0000 0002  lea 2 <.*>,%a0
+                       8: 32   mytext
+   c:  41f9 ffff fffc  lea fffffffc <.*>,%a0
+                       e: 32   mytext
+  12:  41f9 0000 0000  lea 0 <.*>,%a0
+                       14: 32  mydata
+  18:  41f9 0000 0003  lea 3 <.*>,%a0
+                       1a: 32  mydata
+  1e:  41f9 ffff ffff  lea ffffffff <.*>,%a0
+                       20: 32  mydata
+  24:  41f9 0000 0000  lea 0 <.*>,%a0
+                       26: 32  mybss
+  2a:  41f9 0000 0001  lea 1 <.*>,%a0
+                       2c: 32  mybss
+  30:  41f9 ffff fffe  lea fffffffe <.*>,%a0
+                       32: 32  mybss
+
+00000036 <mytext>:
+  36:  4e71            nop
+  38:  4e71            nop
+  3a:  4e71            nop
index 96a8910b104c39fbb6a84a0dca8e326f607b079a..41142165fdd6d1fd3c7c8fe470fbfdd0896b345a 100644 (file)
@@ -1,6 +1,27 @@
-       jmp     mylabel+2
+       lea     mytext,%a0
+       lea     mytext+2,%a0
+       lea     mytext-4,%a0
+       lea     mydata,%a0
+       lea     mydata+3,%a0
+       lea     mydata-1,%a0
+       lea     mybss,%a0
+       lea     mybss+1,%a0
+       lea     mybss-2,%a0
+       .weak   mytext
+mytext:
        nop
-       .weak   mylabel
-mylabel:
        nop
        nop
+
+       .data
+       .word   0x8081
+       .weak   mydata
+mydata:
+       .word   0x8283
+       .word   0x8485
+
+       .bss
+       .skip   6
+       .weak   mybss
+mybss:
+       .skip   2
diff --git a/gas/testsuite/gas/m68k/p3041data.d b/gas/testsuite/gas/m68k/p3041data.d
new file mode 100644 (file)
index 0000000..91b2895
--- /dev/null
@@ -0,0 +1,28 @@
+#name: PR 3041 data
+#objdump: -trs
+
+.*:     file format .*
+
+SYMBOL TABLE:
+00000006  w      \.text 0000 00 0f mytext
+00000014  w      \.data 0000 00 10 mydata
+00000040  w      \.bss  0000 00 11 mybss
+
+RELOCATION RECORDS FOR \[\.data\]:
+OFFSET   TYPE              VALUE 
+00000004 32                mytext
+00000008 32                mytext
+0000000c 32                mytext
+00000010 32                mydata
+00000014 32                mydata
+00000018 32                mydata
+0000001c 32                mybss
+00000020 32                mybss
+00000024 32                mybss
+
+Contents of section .text:
+ 0000 4e714e71 4e714e71                    .*
+Contents of section .data:
+ 0008 12345678 00000000 00000001 fffffffd  .*
+ 0018 00000000 00000003 fffffffe 00000000  .*
+ 0028 00000002 ffffffff                    .*
diff --git a/gas/testsuite/gas/m68k/p3041data.s b/gas/testsuite/gas/m68k/p3041data.s
new file mode 100644 (file)
index 0000000..73cbc39
--- /dev/null
@@ -0,0 +1,27 @@
+       .text
+       nop
+       nop
+       nop
+       .weak   mytext
+mytext:
+       nop
+
+       .data
+       .long   0x12345678
+       .long   mytext
+       .long   mytext+1
+       .weak   mydata
+mydata:
+       .long   mytext-3
+       .long   mydata
+       .long   mydata+3
+       .long   mydata-2
+       .long   mybss
+       .long   mybss+2
+       .long   mybss-1
+
+       .bss
+       .skip   16
+       .weak   mybss
+mybss:
+       .word   1
This page took 0.032349 seconds and 4 git commands to generate.