immunant / IA2-Phase2

5 stars 0 forks source link

Version scripts that hide symbols break linkage for compartmentalized builds #415

Open randomPoison opened 1 month ago

randomPoison commented 1 month ago

If a project has a function foo that is used as an address-taken function that has been rewritten by the rewriter, and the project uses a linker script to mark foo local, then the function gates in libcallgates.so will generate linker errors when they can't find foo in the compartmentalized library. Note that this is basically the same error as in #414, but caused by a linker script instead of a static modifier.

randomPoison commented 1 month ago

The zlib linker script can be seen here: https://github.com/immunant/zlib/blob/1849c2400150304c100af9d3e3b9b92ac0337290/zlib.map

ayrtonm commented 1 month ago

The problem here is basically the same thing as 414 (missing the right type of callgate), but I'm not sure this can be fixed in the rewriter alone. Basically we'll need something similar to IA2_BEGIN_NO_WRAP to get the rewriter to create the correct callgates for these functions.

randomPoison commented 1 month ago

I think this is just something we need to document in the usage docs. The user will have to do some additional source annotation (e.g. add the used attribute) to handle this case since we can't do it automatically, so we should note this limitation and tell the user how to manually fix it.

ayrtonm commented 1 month ago

Right, though I don't think the used annotation by itself does the right thing here.

rinon commented 1 month ago

The simplest thing I can think of is a CLI param for the rewriter that tells it to treat a symbol as internal. Were you thinking of adding an annotation to the sources instead, Ayrton? That works too, probably cleaner, but technically the linker script allows the build system to hide the symbol independently from the source file, so in some configurations it might and in some it might not.