On Tue, Aug 15, 2017 at 1:30 AM, Richard Biener <rguent...@suse.de> wrote: > On Mon, 14 Aug 2017, Ian Lance Taylor wrote: > >> It seems to me that if you keep any section of an SHT_GROUP, you need >> to keep all the sections. Otherwise the section indexes in the group >> will be left dangling. > > Note that all sections are "kept", removed sections are just marked > as SHT_NULL. Which means that indeed some group members might > be SHT_NULL. > > Note that I don't remember if I actually run into any SHT_GROUP > member being necessary when another is not (IIRC this was with > debug types sections or so). I'll double-check and add a comment > where this matters for early-debug (the simple-object code tries > to be more generic but obviously all testing was done with > early-debug section copying in mind).
In general they are SHT_GROUP for a reason, that reason being that if you keep one of the group sections you need to keep all of them. If that didn't matter, there wouldn't be a SHT_GROUP section at all. So I think it would be appropriate that if you keep one of a group you keep all of the group. >> The symbol table handling is pretty awful. Can't you just remove the >> symbols you don't want? You will have to update the sh_info field of >> the SHT_SYMTAB section, which holds the index of the first STB_GLOBAL >> symbol in the table. > > Maybe that's what I was missing, let me see if I can make it work. > It looks like if there's no STB_GLOBAL symbol the index is one after > the last symbol and it seems it is the first ! STB_LOCAL symbol > ("One greater than the symbol table index of the last local symbol > (binding STB_LOCAL)"). > > Ah, and implementing this now I remember why I chose the "awkward" > way. This was to preserve symtab indices to not need to rewrite > relocation sections... There isn't a documented way to make > an "none" symtab entry (eventually duplicating UND might work > but IIRC it messes up ordering as UND is STB_LOCAL and thus may > not appear after the first ! STB_LOCAL symbol). As comments in > the code indicate I tried to mangle things in a way that makes > both GNU ld and gold happy... Bother. > Any suggestion how to improve things when not removing symbols? > (I could of course remove things from the end of the symtab) > Like replacing local symbols with UND and globals with > a COMMON of zero size (and no name)? You can have a UND global symbol, after all. You just shouldn't simply zero out the entire symbol, as that will indeed change the binding to STB_LOCAL. So probably the best approach is to change every unwanted symbol to SHN_UNDEF, keep the binding as is, and zero all the other fields. That should let the linker simply discard the symbol, I hope. > I suppose rewriting relocation sections is possible but I tried > to do as little as necessary (like not actually removing sections). The patch is OK with the above suggestions, assuming they work. Ian