This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ld: Section corrupted with elf64-x86-64 input -> elf32-i386 output


I ran into some weird behavior, most likely a bug, in in admittedly even
weirder setting... So I figured I'd check here if I'm missing something and
that's somehow the expected behavior, before I'd file a bug.

Basically I'm linking elf64-x86-64 files together and outputting a elf32-i386
executable (long story, involving a mix of 32 bit and 64 bit code running bare
metal). Now I noticed that some of my string constants were getting corrupted
during linking, truncated mostly. I've tried to reduce this to a minimal
example to show what happens (tested with debian's 2.25.1 and a recent git

> $ cat a.s
> .section	.rodata.str1.1,"aMS",@progbits,1
> .byte 0x0, 0x0, 0x2, 0x3, 0x0
> .string	"ABCD"
> $ as -o a.o a.s
> $ ld --oformat elf32-i386 -o b a.o
> ld: warning: cannot find entry symbol _start; defaulting to 0000000000400054
> $ objdump -s -j .rodata.str1.1 a.o
> a.o:     file format elf64-x86-64
> Contents of section .rodata.str1.1:
>  0000 00000203 00414243 4400               .....ABCD.
> + objdump -s -j .rodata b
> b:     file format elf32-i386
> Contents of section .rodata:
>  400054 00000203 00414243                    .....ABC

Is there something I'm missing or is this a bug? If the latter, any suggestions
on where I should start looking into the code?

Antoine Kaufmann

Attachment: signature.asc
Description: Digital signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]