AmigaLabs / binutils-gdb

binutils targeted for ppc-amigaos systems (AmigaOS NG like OS4.1).
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
0 stars 0 forks source link

Default behavior of "strip" cause: error : symbol `xxxxxx' required but not present, while adtools's default behavior of strip works #2

Closed kas1e closed 1 year ago

kas1e commented 1 year ago

Simple trying to strip some test binary (compiled previously by current public version of adtools), giving me this issue:

$ ppc-amigaos-strip /amiga/cdplay/my_test_1
ppc-amigaos-strip: /amiga/cdplay/stulT0wP: symbol `SysBase' required but not present
ppc-amigaos-strip: /amiga/cdplay/stulT0wP: no symbols
kas1e commented 1 year ago

I also tried to strip the binary i build by public adtools by as/ld , like that:

$ cat > test.s
   .globl main
main:
        lis %r3,.msg@ha          #
        la %r3,.msg@l(%r3)       # printf("aaaa");
        bl printf                #

        li %r3,0                 # exit(0);
        bl exit                  #

.msg:
        .string "aaaa"
$ ./ppc-amigaos-as.exe test.s -o test.o
$ ./ppc-amigaos-ld.exe -N -q test.o -o test /usr/local/amiga/ppc-amigaos/SDK/newlib/lib/crtbegin.o /usr/local/amiga/ppc-amigaos/SDK/newlib/lib/LibC.a /usr/local/amiga/ppc-amigaos/SDK/newlib/lib/crtend.o

And when i tried to strip ready binary by new strip, i do have that:

$ ppc-amigaos-strip test
ppc-amigaos-strip: styFuX2r: symbol `printf' required but not present
ppc-amigaos-strip: styFuX2r: no symbols

So, any symbol/name_of_function we had in binary bring such error.

kas1e commented 1 year ago

Ok, some progress on issue :

For first, pc-amigaos-strip --strip-unneeded works. It's the default "strip" behavior didn't (which is the same as if we use strip -s or --strip-all).

For second, it is interesting to know, that "strip" as it, works in adtools version. So probably somewhere in the adtools patches, were added something which mean "default strip = --strip-unneeded", but dunno if that the case, actually.

migthymax commented 1 year ago

I tracked it down, the error message from using strip as default comes from the from -q / --emit-relocs options used during linking. If this option isn't used, the strip performs without any errors.

migthymax commented 1 year ago

I reworked how the STRIP_ALL option is handle for the ppc-amigaos target. My first tests seems to indicate that it is a working solution. But I#m bot sure if it even still strips unneeded reloc or just keeps everything to be sure.

migthymax commented 1 year ago

Ok, fixed it. For documentation proposes.

The strip all option never ever strips everything if ppc-amigaos is the target. The main reason for that is, that all executable on the amiga shares the same memory. On other OSes each executable get his own exclusive virtual view on the memory, so for them everything get be fixed in advanced. So for ppc-amigaos everything which cannot be fixed in advanced muts be kept, so that the elf loader (elf.library) can put the executable where it is space is available during loading.

So the main issues to keep the relocation. But the relocations aren't just kept, but even resolved as much it is possible. Because the symbol table even gets striped (below more information about them), the symbols of the relocation are resolved / redirected to address the section containing the data, thus eliminating the symbol from the relocation.

Relocation which are relative, theocratically could be striped. For example relocations for the small data , can be stripped, because the relative access to the register _SDABASE symbol will always be the same regardless where the executable is located in the memory. This is currently no implemented to my knowledge.

For striping the symbol section, on ppc.amigaos not all symbols are striped. There at least three symbols, which needs to survive the strip:

Further link with information about the topic: