freemint / m68k-atari-mint-gcc

Fork of GNU's gcc with support for the m68k-atari-mint target
https://github.com/freemint/m68k-atari-mint-gcc/wiki
Other
27 stars 7 forks source link

undefined reference to `_GLOBAL_OFFSET_TABLE_' #27

Closed th-otto closed 1 year ago

th-otto commented 1 year ago

While trying to compile the FLAC library https://tho-otto.de/crossmint.php#flac i get

/opt/cross-mintelf/lib64/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: ../../src/share/utf8/.libs/libutf8.a(utf8.o): in function `utf8_encode':
utf8.c:(.text.utf8_encode+0x6): undefined reference to `_GLOBAL_OFFSET_TABLE_'
/opt/cross-mintelf/lib64/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: BFD (GNU Binutils for MiNT 20230910) 2.40.90.20230730 assertion fail /home/sebilla/atari/freemint.org/m68k-atari-mint-binutils-gdb/bfd/elf32-m68k.c:3595
/opt/cross-mintelf/lib64/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: BFD (GNU Binutils for MiNT 20230910) 2.40.90.20230730 internal error, aborting at /home/sebilla/atari/freemint.org/m68k-atari-mint-binutils-gdb/bfd/elf32-m68k.c:1832 in elf_m68k_get_bfd2got_entry

/opt/cross-mintelf/lib64/gcc/m68k-atari-mintelf/13.2.0/../../../../m68k-atari-mintelf/bin/ld: Please report this bug.

This only seems to happen with Vincents toolchain, but not with mine (although they should be almost identical now)

th-otto commented 1 year ago

Seems to be caused by missing

#undef  SUBTARGET_OVERRIDE_OPTIONS
#define SUBTARGET_OVERRIDE_OPTIONS                  \
do {                                    \
  if (flag_pic && !TARGET_PCREL)                    \
      error ("%<-f%s%> is not supported on this target",            \
           (flag_pic > 1) ? "PIC" : "pic");             \
} while (0)

in mint.h. Those flags must still be rejected for elf, because the runtime does not support it. Without this, autoconf tests thinks that -fPIC works, and uses it.

vinriviere commented 1 year ago

Regarding to pic/PIC stuff, I wondered if that could be useful for us, considering current lack of shared libraries. I had no idea about that, so I just kept the default config. This hadn't caused trouble until now. I wonder why there was a link error about _GLOBAL_OFFSET_TABLE_. Probably something missing from the linker script. But as we don't want to support pic/PIC for now, the current fix is fine.

Note that demomakers often like pc-relative code, as they can move the programs anywhere in memory without caring about relocations. The option -mpcrel is limited. I wonder if pic/PIC could help them, still without support of shared libraries.

th-otto commented 1 year ago

This hadn't caused trouble until now. I wonder why there was a link error about _GLOBAL_OFFSET_TABLE_. Probably something missing from the linker script.

Sometimes it is explicitly disabled, either in config.guess, or by small patches i already used for the packages. But in this case the configure script just compiled using -fPIC and if that works, those flags are also used to compile (sometimes even if you just build a static library)

I wondered if that could be useful for us,

Not until now. It could be useful even without real shared libs, if you want to produce PIE code. But for that you need a lot of support from mintlib, startup code, and kernel, to set up a dedicated register at all relevant places that loads the address of the GOT. Linker of course also has to be changed (for now, only a script for executables is available, and that has to be changed too to include the relevant sections). And i think it also adds quite some overhead at runtime.

I wonder if pic/PIC could help them

Not the way it is implemented. It way even have the opposite effect: the addresses in the GOT have to be relocated by the loader, before the code is executed.