bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

undefined reference to `__divdi3' #88

Closed th-otto closed 5 years ago

th-otto commented 5 years ago

When using the nix20 runtime library, i get unresolved externals for programs that use for examples utimes():

$ cat foo.c
int main(void)
{
        utimes();
        return 0;
}
$ m68k-amigaos-gcc -m68020 -mcrt=nix20 foo.c
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix.a(utimes.o):(.text+0x4c): undefined reference to `__divdi3'
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix.a(utimes.o):(.text+0x68): undefined reference to `__moddi3'
collect2: error: ld returned 1 exit status

It seems to be a mismatch in the underscores of the symbols:

$ m68k-amigaos-gcc -m68020 -mcrt=nix20 -print-libgcc-file-name
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm020/libgcc.a

$ m68k-amigaos-nm -A /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm020/libgcc.a | grep __divdi3
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm020/libgcc.a:_divdi3.o:00000000 T ___divdi3

So the function is there, but exported with 3 underscores.

There is another strange thing:

$ m68k-amigaos-gcc -m68020-60 -mcrt=nix20 -print-libgcc-file-name
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libgcc.a

So when using -m68020-60, it links the library in the main directory, not the one in /libm020

bebbo commented 5 years ago

please use -Xlinker --verbose |& grep succeeded to determine which libraries are really used since -print-libgcc-file-name does not know about the linkers multilib capabilities.

The linker is pretty stupid and searches every library only once. That's why each one has to be listed several times... and often is - as you can see - not often enough^^

Add -lnix -lgcc as a workaround:

m68k-amigaos-gcc -Os utimes.c -o utimes -v -m68020-60 -mcrt=nix20 -Xlinker --verbose -lnix -lgcc |& grep succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/ncrt0.o succeeded
attempt to open /tmp/cc8nS89B.o succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm020/libgcc.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix20.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnixmain.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/lib/libm020/libstubs.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm020/libgcc.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/lib/libm020/libstubs.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/lib/libamiga.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix20.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix20.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libnix20.a succeeded
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/lib/libm020/libstubs.a succeeded
attempt to open /opt/amiga/m68k-amigaos/libnix/lib/libm020/libm.a succeeded
th-otto commented 5 years ago

Hm yes, adding -lnix worked. Would it be possible to change the spec file of gcc accordingly? I encountered the problem when trying build flac, which does not only build a library, but also some tools. Having to add that switch to all recipes for such packages would be cumbersome.

Or alternatively, add those functions to libgcc instead, where they actually belong. Either by hacking the Makefiles of gcc, or (maybe easier) by just extracting the members of libnix.a and adding them to libgcc.a before installing.

bebbo commented 5 years ago

Hm yes, adding -lnix worked. Would it be possible to change the spec file of gcc accordingly? I encountered the problem when trying build flac, which does not only build a library, but also some tools. Having to add that switch to all recipes for such packages would be cumbersome.

The ticket is still open - and I only suggested a workaround... /shrug

bebbo commented 5 years ago

it's not fixed yet.

th-otto commented 5 years ago

Oh sry, I thought you wanted to convince me to close it, with your comment above.

bebbo commented 5 years ago

Oh sry, I thought you wanted to convince me to close it, with your comment above.

Misunderstandings exist to misunderstand each other.

bebbo commented 5 years ago

please test

th-otto commented 5 years ago

Yes, seems to work, thank you!