bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

libbfd refuses to load some HUNK files #43

Open antekone opened 2 months ago

antekone commented 2 months ago

I think that this fork of libbfd can have a bug, though I'm sorry if the fault is on me.

The core problem I have is that strip (nor objdump) doesn't work for files generated by m68k-amigaos-g++ from the 13.2 branch:

~/dev/amiga> m68k-amigaos-g++ hello.cpp -o hello -s -O3 -mcrt=nix13 && m68k-amigaos-strip hello
m68k-amigaos-strip: hello: file format not recognized

~/dev/amiga> file hello
hello: AmigaOS loadseg()ble executable/binary

I've debugged a little bit and I've found that the amigaos.c vec is refusing to load this HUNK file. The refusal is generated by this line:

https://github.com/bebbo/binutils-gdb/blame/101c27d0af524ce77cf34ca73cdfdfbbc5361ec2/bfd/amigaos.c#L1100

The hunk_type in the iteration that generates an error is HUNK_RELOC32 for my case.

antekone commented 2 months ago

HUNK files generated by g++ look like the following:

hunk 000003f3,      HUNK_HEADER,          0
4 sections, 0 - 3 
sizes: 20424, 320, 92, 40488
hunk 000003e9,        HUNK_CODE,      20424
hunk 000003ec,     HUNK_RELOC32,        828
hunk 000003f0,      HUNK_SYMBOL,          8
HUNK_END
hunk 000003ea,        HUNK_DATA,        320
hunk 000003ec,     HUNK_RELOC32,         16
hunk 000003f0,      HUNK_SYMBOL,         16
HUNK_END
hunk 000003eb,         HUNK_BSS,         92
hunk 000003f0,      HUNK_SYMBOL,          8
HUNK_END
hunk 000003f1,       HUNK_DEBUG,      40488
hunk 000003ec,     HUNK_RELOC32,       7016
hunk 000003f0,      HUNK_SYMBOL,         20
HUNK_END

Is HUNK_DEBUG allowed as a first block inside a hunk? From various sources it seems that only CODE, DATA and BSS are allowed as first blocks in each hunk in a "load" file? (at least in OS 1.3, but that assumption is also followed by libbfd).

bebbo commented 1 month ago

the OS does not like relocations in DEBUG hunks... ... should be ok now