Ticket #29 (closed defect: fixed)

Opened 4 years ago

Last modified 2 years ago

ld returns 'bad relocation section name' when extern is in C lib.

Reported by: michaelryan Assigned to: mu@tortall.net
Priority: P2 Milestone: 0.4.0
Component: Object Format: elf Version: 0.3.0
Severity: normal Keywords:
Cc:

Description

system is fedora core 1; gcc 3.3.2 20031022; AMD Opteron

[root@opteron yasm]# yasm -felf -mamd64 test.n
[root@opteron yasm]# gcc -m64 -o test test.o
/usr/bin/ld: test.o: bad relocation section name `.rel.text'
[root@opteron yasm]# 

        [BITS 64]
        extern  printf
        [SECTION .text] 
        global main
main:
;
; Standard entry linkage
;
        push    rbp
        mov     rbp,rsp
        push    rbx
        push    rsi
        push    rdi

        lea     r8,[Hello]
        push    r8
        call    printf
        add     esp,8
;
; Standard return linkage
;
        pop     rdi
        pop     rsi
        pop     rbx
        mov     rsp,rbp
        pop     rbp
        ret
        [SECTION .data]
Hello:  db      'Hello, World',10,0

Attachments

Change History

03/14/04 11:21:44 changed by michaelryan

*** Bug 28 has been marked as a duplicate of this bug. ***

03/14/04 13:12:34 changed by mu

Hello Michael,
Could you please compile and attach the .o file for the following C file?
Per your example, I suspect the compilation line will be "gcc -m64 -c extern.c"
but I haven't had any 64bit machines to test on.

Thanks!
-m

extern.c:
---------
extern int exint;
extern int exfunc(char *, ...);
 
int main(int argc, char *argv[])
{
    return exfunc("Test", exint);
}

03/15/04 18:40:21 changed by mu

Looks like the primary reason here is that gcc is expecting a .rela.text instead
of a .rel.text (or at least that's what it creates). I'll talk to Pete some and
see what input he has. I'm largely just curious why this hasn't been reported as
a problem before - perhaps we just haven't had anyone seriously use amd64 elf
output yet. If that's the case, glad to have you with us!

03/19/04 04:28:04 changed by michaelryan

Changing the name in elf-objfmt.c at lines 470-472, as follows, allows the YASM-
generated object module to link successfully:
  
    relname_len = strlen(sectname)+6;
    relname = yasm_xmalloc(relname_len);
    snprintf(relname, relname_len, ".rela%s", sectname);
---------------------------------------------------------
[root@opteron yasm]# make
yasm --machine=AMD64 --oformat=elf --objfile=test.o test.n
gcc -m64 -o test test.o
[root@opteron yasm]# ./test
Hello, World
---------------------------------------------------------
        extern  printf
        [SECTION .text]
        global main
main:
        push    rbp
        mov     rbp,rsp
        push    rbx
        push    rsi
        push    rdi
        
        lea     rdi,[Hello]
        xor     eax,eax
        call    printf

        pop     rdi
        pop     rsi
        pop     rbx
        xor     rax,rax
        leave
        ret
        [SECTION .data]
        global  Hello
Hello:  db      'Hello, World',10,0

[root@opteron yasm]# 

03/19/04 22:33:11 changed by mu

That the s/.rel/.rela/ patch works is purely by accident. The Rel and Rela
section types are different in format as well as name; the latter including an
addend per record that the former lacks.
(ElfNN_Addr r_offset, ElfNN_*word r_info[, ElfNN_S*word r_addend])

Furthermore, there's an entry describing a section type as SHT_REL or SHT_RELA,
and this was not similarly updated. Actually i'd guess that's why this worked.
Still the question at hand is why it's using Rela when other x86 based
relocations use Rel.

I do thank you for the attempt though; it's interesting information at the
least, even if it is a pretty hacky workaround, and it sounds like it lets you
test the rest of yasm even before we figure out the right solution here.

10/15/04 06:33:03 changed by mu

  • status changed from new to closed.
  • resolution set to fixed.

This is what I get for forgetting about bugzilla. This was reported again by another user, and this time I fixed it. See [1160] for the support for .rela.text for AMD64.


Add/Change #29 (ld returns 'bad relocation section name' when extern is in C lib.)