Re: #define of 'extern' in stackgap.c
Felix von Leitner <[email protected]> Wed, 16 Mar 2016 15:30:30 +0100
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
Thus spake Enrico Scholz ([email protected]): > lib/stackgap.c contains a > | #define extern __hidden__ > at the start of file. This is a problem I'm still working on. The root problem is that statically linked ELF programs are loaded at a fixed address. This is an ELF restriction. However, it is also possible to have an ELF shared object (usually a shared library) and load that like a regular binary. Then the kernel can load it at a random address, which is good for security. On glibc, this is enabled with -flto. However, having a shared library has its own problems. Most importantly, it has an ELF interpreter (ld.so) that does the relocations. The main benefit of using dietlibc is that the binaries are self contained, so having an ld.so is out. So I added some code to stackgap.c to do this. However, if you want to link everything into one binary (shared library in this case) and there are no external references, then accessing symbols indirectly via PLT and GOT is wasteful and unnecessary. So we want gcc to not do it. For that, I tried marking all symbols as hidden. The problem is: how do you declare, in a head file, that there is an "external" hidden symbol? The second you put "extern" there, -fvisibility=hidden is ignored and gcc tries to resolve dynamically at run time. So I tried playing around with variout options, and this is one of those. I don't have a solution yet. Felix