Wael Yehia via llvm-dev
2021-Jul-26 17:59 UTC
[llvm-dev] [libLTO] accessing llvm.global_ctors
-----"Steven Wu" <stevenwu at apple.com> wrote: ----- To: "Wael Yehia" <wyehia at ca.ibm.com> From: "Steven Wu" <stevenwu at apple.com> Date: 07/26/2021 12:22PM Cc: "Fangrui Song" <maskray at google.com>, llvm-dev at lists.llvm.org Subject: [EXTERNAL] Re: [llvm-dev] [libLTO] accessing llvm.global_ctors> It also sounds like that you just need to know if the object file has constructor or not, but don't really care anything more than that?yes> Can you read the section name from the IRSymtab to figure out if that is a constructor/destructor or not?Is this a suggestion of how to implement the query I'm after? My initial thought was to simply check for the presence of the symbols `llvm.global_ctors` and `llvm.global_dtors` in the ModuleSymbolTable in the LTOModule.>> Certain linker flag forces it to include all archive members that have a constructor or destructor. I agree it's strange. > > Is it possible to disclose what linker and what platform that is? You don't have to but it would be easier to maintain if you can document this behavior that is unique to the platform you are looking at.The linker is the system linker on AIX, and the option is -bcdtors:all (documented here: https://www.ibm.com/docs/en/aix/7.2?topic=l-ld-command)
Steven Wu via llvm-dev
2021-Jul-26 20:03 UTC
[llvm-dev] [libLTO] accessing llvm.global_ctors
> On Jul 26, 2021, at 10:59 AM, Wael Yehia <wyehia at ca.ibm.com> wrote: > > > > > -----"Steven Wu" <stevenwu at apple.com> wrote: ----- > To: "Wael Yehia" <wyehia at ca.ibm.com> > From: "Steven Wu" <stevenwu at apple.com> > Date: 07/26/2021 12:22PM > Cc: "Fangrui Song" <maskray at google.com>, llvm-dev at lists.llvm.org > Subject: [EXTERNAL] Re: [llvm-dev] [libLTO] accessing llvm.global_ctors > >> It also sounds like that you just need to know if the object file has constructor or not, but don't really care anything more than that? > yes > > >> Can you read the section name from the IRSymtab to figure out if that is a constructor/destructor or not? > Is this a suggestion of how to implement the query I'm after? > My initial thought was to simply check for the presence of the symbols `llvm.global_ctors` and `llvm.global_dtors` in the ModuleSymbolTable in the LTOModule.The reason why I don't want to do that is because they are not real symbols and linker do not know how to resolve them. You could stamp a different attribute on them but the old linker will not be able to understand them. If the only thing you care about is checking the existence of ctors and dtors, and all you need is using fullLTO with libLTO, reading intrinsics is probably fine. ThinLTO or using the new C++ LTO interface doesn't really use ModuleSymbolTable. Also trying to read what the constructors are will be quite expensive from those functions because they needs to be materialized so you don't want to do that when you just querying the symbol names> > >>> Certain linker flag forces it to include all archive members that have a constructor or destructor. I agree it's strange. >> >> Is it possible to disclose what linker and what platform that is? You don't have to but it would be easier to maintain if you can document this behavior that is unique to the platform you are looking at. > The linker is the system linker on AIX, and the option is -bcdtors:all (documented here: https://www.ibm.com/docs/en/aix/7.2?topic=l-ld-command) >Looks reasonable. Just remember to mention that in your patch. Steven
Wael Yehia via llvm-dev
2021-Jul-26 22:39 UTC
[llvm-dev] [libLTO] accessing llvm.global_ctors
-----"Steven Wu" <stevenwu at apple.com> wrote: ----- To: "Wael Yehia" <wyehia at ca.ibm.com> From: "Steven Wu" <stevenwu at apple.com> Date: 07/26/2021 04:03PM Cc: "Fangrui Song" <maskray at google.com>, "LLVM-DEV LIST" <llvm-dev at lists.llvm.org> Subject: [EXTERNAL] Re: [llvm-dev] [libLTO] accessing llvm.global_ctors>> On Jul 26, 2021, at 10:59 AM, Wael Yehia <wyehia at ca.ibm.com> wrote: >> >> >> >> >> -----"Steven Wu" <stevenwu at apple.com> wrote: ----- >> To: "Wael Yehia" <wyehia at ca.ibm.com> >> From: "Steven Wu" <stevenwu at apple.com> >> Date: 07/26/2021 12:22PM >> Cc: "Fangrui Song" <maskray at google.com>, llvm-dev at lists.llvm.org >> Subject: [EXTERNAL] Re: [llvm-dev] [libLTO] accessing llvm.global_ctors >> >>> It also sounds like that you just need to know if the object file has constructor or not, but don't really care anything more than that? >> yes >> >> >>> Can you read the section name from the IRSymtab to figure out if that is a constructor/destructor or not? >> Is this a suggestion of how to implement the query I'm after? >> My initial thought was to simply check for the presence of the symbols `llvm.global_ctors` and `llvm.global_dtors` in the ModuleSymbolTable in the LTOModule. > >The reason why I don't want to do that is because they are not real symbols and linker do not know how to resolve them. You could stamp a different attribute on them but the old linker will not be able to understand them.Just to be clear, i'm not proposing that these two symbols start being accessible through the `lto_module_get_[num_symbols|symbol_name|symbol_attribute]` functions (which would make them visible to a linker). I'm proposing something like: lto_bool_t lto_module_has_ctor_dtor(lto_module_t mod) { return unwrap(mod)->hasCtorDtor(); } bool LTOModule::hasCtorDtor() { // either (1) traverse `ModuleSymbolTable SymTab` or // (2) compute and cache the answer when LTOModule::parseSymbols runs }