This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add a tool called WrapperGen.
ClosedPublic

Authored by sivachandra on Jul 29 2020, 7:42 AM.

Details

Summary

This tool will be used to generate C wrappers for the C++ LLVM libc
implementations. This change does not hook this tool up to anything yet.
However, it can be useful for cases where one does not want to run the
objcopy step (to insert the C symbol in the object file) but can make use
of LTO to eliminate the cost of the additional wrapper call. This can be
relevant for certain downstream platforms. If this tool can benefit other
libc platforms in general, then it can be integrated into the build system
with options to use or not use the wrappers. An example of such a
platform is CUDA.

Diff Detail

Event Timeline

sivachandra created this revision.Jul 29 2020, 7:42 AM
sivachandra requested review of this revision.Jul 29 2020, 7:42 AM

This looks good. I wonder though how we will deal with global variables. Those can't be easily wrapped like functions can.

libc/utils/tools/WrapperGen/Main.cpp
20–22

How do you imagine we will invoke this tool? Our list of function names is in TableGen so it wouldn't be easy to run this over every function name. Will this be called from add_entrypoint_object then?

59

I think this should be fine because all we care about it ABI compatibility, and we're only including the src/ headers not the include/ ones so the compiler wont complain there.

This looks good. I wonder though how we will deal with global variables. Those can't be easily wrapped like functions can.

Yes, global variables question is open if we have to support them in some manner. The one we have currently, errno which not really global but like one, is accessed by the extension function __errno_location. So, we are good in this case. If there are other global variables we need to support (nothing comes to my mind), we can take that up at that time.

libc/utils/tools/WrapperGen/Main.cpp
20–22

Yes, the build rules will be the right place to hook this up. The downstream use case I am working with does exactly that.

59

Right. In the existing code, there are no examples which break. But, added this TODO just in case. Does not add value you think?

abrachet accepted this revision.Jul 30 2020, 12:58 PM

This looks good. I wonder though how we will deal with global variables. Those can't be easily wrapped like functions can.

Yes, global variables question is open if we have to support them in some manner. The one we have currently, errno which not really global but like one, is accessed by the extension function __errno_location. So, we are good in this case. If there are other global variables we need to support (nothing comes to my mind), we can take that up at that time.

There are the stupid globals related to getopt :). Indeed solvable later.

libc/utils/tools/WrapperGen/Main.cpp
59

No preference either way.

This revision is now accepted and ready to land.Jul 30 2020, 12:58 PM
This revision was landed with ongoing or failed builds.Jul 30 2020, 4:07 PM
This revision was automatically updated to reflect the committed changes.