#459·toaruos

Rebuild toolchain for PIE support

Author: klangeCreated May 20, 2026Updated Jun 8, 2026

In ac6f7da55e094ffdfbcc5c16dd84eeb56de4b6a5, I pushed a change to ignore relocations in read-only segments, which I knew was just going to be working around a configuration issue in the toolchain, though I misidentified the source in the commit message.

The real issue stems from start files; particularly, that gcc is linking against crtbegin.o and crtend.o instead of crtbeginS.o and crtendS.o.

This is because our spec definitions only check for shared and !shared, but PIE is actually separate from both of those, so I think we need something like this:

c
#define STARTFILE_SPEC \
    "%{shared:; \
       static:crt0.o%s;\
       " PIE_SPEC ":Scrt0.o%s; \
       :crt0.o%s} " \
    "crti.o%s " \
    "%{static:crtbegin.o%s; \
       shared|" PIE_SPEC ":crtbeginS.o%s; \
       :crtbegin.o%s} "

#define ENDFILE_SPEC \
    "%{static:crtend.o%s; \
       shared|" PIE_SPEC ":crtendS.o%s; \
       :crtend.o%s} " \
    "crtn.o%s "

We should also add the aforementioned Scrt0, which ensures the reference to main gets a viable relocation, though I'm not sure that it is necessary.