Bug 10558 - gas emits invalid reloc which causes ld to abort
Summary: gas emits invalid reloc which causes ld to abort
Status: RESOLVED OBSOLETE
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-25 06:39 UTC by Matt Thomas
Modified: 2022-11-25 03:32 UTC (History)
1 user (show)

See Also:
Host: x86_64--netbsd
Target: mips64el--netbsd
Build: x86_64--netbsd
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Thomas 2009-08-25 06:39:33 UTC
The follow mips asm fragment when assembled and link -shared the following error messages from ld:

mips64el--netbsd-as -KPIC -mabi=new -o devname.so devname.o
mips64el--netbsd-ld: error: /tmp/devname.so contains a reloc (0x0000000000000914) for section 
.text that references a non-existent global symbol
mips64el--netbsd-ld: final link failed: Bad value

        .file   1 "devname.c"
        .section .mdebug.abiN32
        .previous
        .abicalls
        
        addiu   $sp,$sp,-16
        move    $12,$28
        lui     $28,%hi(%neg(%gp_rel(_devname)))
        addu    $28,$28,$25
        addiu   $28,$28,%lo(%neg(%gp_rel(_devname)))
        lw      $2,%got_page($LC4+5)($28)
        addiu   $2,$2,%got_ofst($LC4+5)
        move    $28,$12
        j       $31
        addiu   $sp,$sp,16

        .set    macro
        .set    reorder
        .end    _devname
        .size   _devname, .-_devname

However, if the follow diff is applied then the error goes away.

@@ -25,8 +25,9 @@
        lui     $28,%hi(%neg(%gp_rel(_devname)))
        addu    $28,$28,$25
        addiu   $28,$28,%lo(%neg(%gp_rel(_devname)))
-       lw      $2,%got_page($LC4+5)($28)
-       addiu   $2,$2,%got_ofst($LC4+5)
+$LC5=$LC4+5
+       lw      $2,%got_page($LC5)($28)
+       addiu   $2,$2,%got_ofst($LC5)
        move    $28,$12
        j       $31
        addiu   $sp,$sp,16

Obviously that change should not caused anything to change but it did.  It seems that when the reloc is 
emitted, the $LC4 + 5 should have been changed to .rodata.str1.8 + offset($LC4) + 5.  This bug exists 
in 2.16 and in 2.19 and on HEAD.
Comment 1 Matt Thomas 2009-08-25 20:28:57 UTC
This is actually a bug in objcopy:

gas/as-new -KPIC -mabi=n32 -o /tmp/devname.so /tmp/devname.s       
ld/ld-new -shared -o /tmp/devname.so.1 /tmp/devname.so             
binutils/objcopy -x /tmp/devname.so                                
ld/ld-new -shared -o /tmp/devname.so.1 /tmp/devname.so 
ld/ld-new: error: /tmp/devname.so contains a reloc (0x0000000000000914) for section .text that 
references a non-existent global symbol
ld/ld-new: final link failed: Bad value
Comment 2 Matt Thomas 2009-08-25 20:37:03 UTC
However I'd like re-iterate that gas should have emitted the reloc with the local symbol in the first place.
Comment 3 Alan Modra 2009-10-29 05:41:45 UTC
Your asm snippet doesn't assemble.  I added a .ent directive, and definitions
for _devname and $LC4, and current mainline then assembles and links OK.  Please
correct your testcase.
Comment 4 Alan Modra 2022-11-25 03:32:18 UTC
.