Wrap for symbol bisect instead of weak linking #291
Labels
c++
Involves touching c++ code
documentation
Involves touching documentation
enhancement
make
Involves touching GNU Makefiles
python
Involves touching python code
tests
Involves touching tests
Feature Request
Describe the new feature:
Our current approach for symbol bisect is to convert some symbols into weak symbols for the two object files and link them together into the executable. This approach tends to fail 25% of the time because of violations of the compiler single translation unit. Can we do it differently?
I propose an alternative strategy instead of mixing and matching the strong function symbols. Suppose the object file from the baseline compilation is
baseline.o
and the object file from the variable compilation isoptimized.o
. My proposal is to rename all global function symbols with a prefix (e.g.,__real_baseline_
forbaseline.o
) for both object files and then synthesize a file full of wrapper functions choosing between the renamed symbols based on what the bisect search wants.With this approach, we would probably want the symbols that are not wrapped to become local symbols so that we don't have problems of partially inlined functions and then calling the wrong one.
Suggested change:
To do this, (Gene Cooperman helped come up with this idea) we can use
objcopy
similarly to how it is used now. Suppose I just want to wrap around symbolfoo
found in bothbaseline.o
andoptimized.o
(both of them were compiled with-fPIC
). I would do something like the following:The wrap code would be something like this (call it
wrap.c
):Compile
wrap.c
with something likeThen link together all three object files (
wrap.o
,baseline_for_wrap.o
, andoptimized_for_wrap.o
) into the executable.We would want some way of controlling the variable
foo_choose_baseline
from theflit_bisect.py
tool. I'm thinking it would be through an environment variable, but it could also be that it is hard-coded in thewrap.c
file and we generate a newwrap.c
file for each bisect step. The former approach would only require one link step and the latter would require many link steps for the duration of the bisect algorithm.Note: we should probably mark the symbols not wrapped as local symbols or else bad things may happen.
Question: would this cause problems with the line number detection? We would need to change the reporting to report the symbol being wrapped instead of the wrapper function. Also, we would need to remove the rename prefix when reporting it to the user (Ugh).
Alternative approaches:
The flag
--allow-multiple-definitions
in the suggestion above makes me a bit uneasy. It would probably work, but maybe not. One thing to note is that after marking the other symbols as local symbols, we may not need that flag.An alternative approach could be to try to make the symbols being wrapped as a renamed symbol in the object file, but at the call site, make those point to the original name with an added undefined symbol (that would be resolved by the linker). Above, we are relying on the weak-over-strong symbol approach for the wrapped symbols, but we can maybe do better than that. I couldn't find a way to do it with
objcopy
orstrip
, but I could make my own elf editor that could do it (maybe). This would perhaps be more robust (assuming I edit elf files correctly), but not nearly as easy to do.The text was updated successfully, but these errors were encountered: