#324
__attribute__((section)) is silently ignored, breaking section-based registration
The section attribute has no effect: the data is emitted, but not into the named section, and no diagnostic is produced.
__attribute__((section("mysection"), used))
static const char blob[16] = "HELLO_SECTION";
const char *get(void) { return blob; }
$ clang -c -o sect.o sect.c # Fil-C
$ readelf -S sect.o | grep -c mysection -> 0
$ strings sect.o | grep -c HELLO_SECTION -> 1
$ gcc -c -o sect.o sect.c # system GCC 13.3, same source
$ readelf -S sect.o | grep -c mysection -> 1
$ strings sect.o | grep -c HELLO_SECTION -> 1Impact: any library that registers things by placing records in a named section and walking it later stops working, with no build-time indication. Concretely, it breaks Qt's entire plugin system -- Q_PLUGIN_METADATA puts plugin metadata in a .qtmetadata section and Qt locates plugins by scanning for it, so every plugin is rejected as "not a Qt plugin" and no GUI application can start at all. Test registries and similar _start/_stop designs would fail the same way.
A diagnostic on an unsupported section attribute would be much easier to diagnose than the silent miscompile, if honouring it is not practical.
Yeah, the way I've modified projects that use this feature is to switch them to a global constructor based registration instead.
But I agree - if there was a way to make the section thing work memory-safely, then that would be better!