__attribute__((used)) and druntime

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 11 08:35:40 PDT 2015


I've been looking into compiling smaller executables, and the 
trick I learned from watching sessions from the last DConf is to 
use the KEEP symbol in a linker script with something like 
gc-sections. So at the compilation stage, symbols are put in 
different sections, a linker script marks some symbols to be kept 
if they are not referenced, and then unreferenced symbols are 
removed, resulting in sometimes very small executables.

The problem is that if you don't KEEP some symbols for druntime, 
or in your own program, you can run into errors because symbols 
which weren't apparently referenced now get used and your program 
breaks. I was just thinking, "There must be a GCC extension for 
doing this without a linker script," I *think* there might be.

 From what I just read, __attribute__((used)) in GCC should do the 
job, and I think it should be usable from GDC with its attribute 
pragmas. I believe there's also an attribute for putting symbols 
in particular sections. I'm wondering, supposing I'm not 
completely wrong and this actually works, would it behoove us to 
add some version() blocks for GDC (Also LDC?) in druntime and 
flag all of the symbols like this appropriately, so that creating 
executables with gc-sections will Just Work in some cases without 
a linker script?

What do people think? Am I on to something, or I am just making 
fanciful ideas which won't work?


More information about the Digitalmars-d mailing list