how to annotate a compilation output (object/library file) with compiler annotations?

70 views Asked by At

Is there a (if possible standard) way to annotate a compiler output (eg object file.o, library file.a, or shared library libfile.so) with user defined attributes, for example with a json string (embedded in some section of the object file) that contains metadata for the object:

eg: as compiler (clang/gcc/dmd/ldc/gdc etc), version (eg: 2.072), whether c++11 was used, optimization and compiler flags, etc.

eg: {"compiler" : "dmd", "version" : "2.072", "flags" : "-O -debug"}

Use cases:

  • either the linker ld or some other user defined tool could use this metadata to give informative warnings or errors when attempting to link together several libraries whose attributes don't match (eg when linking libraries compiles with -std=c++11 with others compiled without this)

  • this would provide much more user friendly error messages compared to the usual hard to debug undefined symbol errors, eg: undefined reference to llvm::Twine::str[abi:cxx11]() https://github.com/ldc-developers/ldc/issues/1928 or other errors that are due to compilation flag mismatches (eg missing -debug from https://github.com/rejectedsoftware/vibe.d/issues/740#issuecomment-268039416)

  • make it possible for tools to read the embedded metadata and find the most appropriate matching libraries to link when multiple ones are available

NOTE: the only thing I could find was https://gcc.gnu.org/onlinedocs/gccint/LTO-object-file-layout.html but not sure if that's relevant or how I would write (and later read) such user defined attributes:

Command line options (.gnu.lto_.opts): This section contains the command line options used to generate the object files

0

There are 0 answers