News for hackers. Stuff that matters.
Re:C++: Associative map containers with compile-time lookup by quotemstr on Tuesday October 23, 2018 @06:35AM (#18282222)
Not exactly as fast. Without -Bsymbolic, a global variabile with global symbol visibility gets its own GOT entry, meaning access to your global goes through an indirection table that supports ELF symbol interposition. (Which, IMHO, was a bad idea, but you can't unbreak an egg.) With a data structure like this (or with a conventional "struct globals"), there's one symbol at the ELF level to look up instead of one per variable, so your code might end up doing fewer GOT lookups.

The last paragraph was just arcana though. You should be passing -fvisibility=hidden and explicitly exporting from your DSO only the symbols you might legitimately expect some other DSO to use, obviating the issue.

Re:C++: Associative map containers with compile-time lookup by hogliux on Tuesday October 23, 2018 @06:41AM (#18282247)
Thanks, I'll have a look at this!
Re:C++: Associative map containers with compile-time lookup by jstimpfle on Tuesday October 23, 2018 @08:10AM (#18282647)
Look at the approach from my other comment. Requires only 1 symbol.
Re:C++: Associative map containers with compile-time lookup by hogliux on Tuesday October 23, 2018 @08:16AM (#18282671)
Both your approach and the `semi::static_map` will generate the same type of load instruction. In both cases, the compiler knows the offset of the values in memory at compile-time. The number of symbols is not really important here.