[Openmp-commits] [PATCH] D93727: [OpenMP] Add using bit flags to select Libomptarget Information
Vyacheslav Zakharin via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jan 26 12:49:55 PST 2021
vzakhari added inline comments.
================
Comment at: openmp/libomptarget/include/Debug.h:54-63
+static inline uint32_t getInfoLevel() {
+ static uint32_t InfoLevel = 0;
+ static std::once_flag Flag{};
+ std::call_once(Flag, []() {
+ if (char *EnvStr = getenv("LIBOMPTARGET_INFO"))
+ InfoLevel = std::stoi(EnvStr);
+ });
----------------
jhuber6 wrote:
> jhuber6 wrote:
> > vzakhari wrote:
> > > Hello. Am I the only one who is getting `libomptarget.rtl.x86_64.so` build fail with `-DCMAKE_BUILD_TYPE=Debug`?
> > >
> > > > ld: CMakeFiles/omptarget.rtl.x86_64.dir/__/generic-elf-64bit/src/rtl.cpp.o: in function `getInfoLevel()::{lambda()#1}::operator()() const':
> > > > .../openmp/libomptarget/include/Debug.h:61: undefined reference to `getInfoLevel()::InfoLevel'
> > > > ld: CMakeFiles/omptarget.rtl.x86_64.dir/__/generic-elf-64bit/src/rtl.cpp.o: relocation R_X86_64_PC32 against undefined symbol `_ZZL12getInfoLevelvE9InfoLevel' can not be used when making a shared object; recompile with -fPIC
> > >
> > > Here is a small reproducer:
> > >
> > > ```
> > > #include <mutex>
> > >
> > > static inline uint32_t getInfoLevel() {
> > > static uint32_t InfoLevel = 0;
> > > static std::once_flag Flag{};
> > > std::call_once(Flag, []() {
> > > InfoLevel = 1;
> > > });
> > >
> > > return InfoLevel;
> > > }
> > > ```
> > >
> > > I cannot build a shared library from it using gcc: g++ -fPIC -std=c++14 test.cpp -shared -o test.so
> > >
> > >
> > > > ld: /tmp/ccBpTXXs.o: relocation R_X86_64_PC32 against undefined symbol `_ZZL12getInfoLevelvE9InfoLevel' can not be used when making a shared object; recompile with -fPIC
> > >
> > >
> > > The issue is reproducible with GCC 5.5.0 and 6.5.0, and does not reproduce with 7.3.0. I believe LLVM's minimal requirement is 5.1, so it is a problem.
> > >
> > > The issue seems to be caused by the fact that getInfoLevel() is not referenced in `openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp`
> > I have no issues compiling the reproducer you provided. It compiles without errors locally and here https://godbolt.org/z/oEKq3E for the compilers you listed. There might be a problem when the compiler doesn't create a static variable when the function in unused. Does the problem go away if you create a dummy usage of getInfoLevel()?
> Actually you're right, it doesn't work on Godbolt, the error went off screen and didn't list as an error in the compilation. It definitely works locally on the machine I tested it on so who knows what's up with that. The error goes away if I just add a dummy usage to force the compiler to actually generate a symbol for InfoLevel. It's a solution but probably not the best.
Of course, it does compile with a dummy reference. I guess you have more recent GCC on your machine. The issue seems to be fixed somewhere between 6.5.0 and 7.1.0.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93727/new/
https://reviews.llvm.org/D93727
More information about the Openmp-commits
mailing list