Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libomptarget] Support BE ELF files in plugins-nextgen #85246

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

uweigand
Copy link
Member

Code in plugins-nextgen reading ELF files is currently hard-coded to assume a 64-bit little-endian ELF format. Unfortunately, this assumption is even embedded in the interface between GlobalHandler and Utils/ELF routines, which use ELF64LE types.

To fix this, I've refactored the interface to use generic types, in particular by using (a unique_ptr to) ObjectFile instead of ELF64LEObjectFile, and ELFSymbolRef instead of ELF64LE::Sym.

This allows properly templating over multiple ELF format variants inside Utils/ELF; specifically, this patch adds support for 64-bit big-endian ELF files in addition to 64-bit little-endian files.

Code in plugins-nextgen reading ELF files is currently hard-coded to assume
a 64-bit little-endian ELF format. Unfortunately, this assumption is even
embedded in the interface between GlobalHandler and Utils/ELF routines,
which use ELF64LE types.

To fix this, I've refactored the interface to use generic types,
in particular by using (a unique_ptr to) ObjectFile instead of
ELF64LEObjectFile, and ELFSymbolRef instead of ELF64LE::Sym.

This allows properly templating over multiple ELF format variants inside
Utils/ELF; specifically, this patch adds support for 64-bit big-endian
ELF files in addition to 64-bit little-endian files.
@uweigand uweigand requested a review from jhuber6 March 14, 2024 15:30
@llvmbot llvmbot added the openmp:libomptarget OpenMP offload runtime label Mar 14, 2024
Comment on lines +152 to +155
static Expected<std::optional<ELFSymbolRef>>
getHashTableSymbol(const ELFObjectFile<ELFT> &ELFObj,
const typename ELFT::Shdr &Sec, StringRef Name) {
const ELFFile<ELFT> &Elf = ELFObj.getELFFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part changed? It's internal so it should be using the "actual" ELF format and not the Object file wrapper I would assume.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to at some point convert a ELFT::Sym pointer into a ELFSymbolRef. This requires access to both the symbol table (section header) containing the symbol, and the Object file wrapper (which provides the ELFObj.toSymbolRef routine that actually creates the ELFSymbolRef. We could move the call to toSymbolRef to the caller, but there we don't have ready access to the symbol table, so we'd have to re-compute it again. Doing it inside getHashTableSymbol seems the lesser change to me.

Comment on lines +283 to +286
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(&Obj))
return getSymbolImpl(*ELFObj, Name);
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(&Obj))
return getSymbolImpl(*ELFObj, Name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not just do getELFFile here like before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the ObjectFile wrapper so we can call toSymbolRef, as discussed above.

@uweigand uweigand merged commit 611c62b into llvm:main Mar 14, 2024
6 checks passed
uweigand added a commit that referenced this pull request Mar 14, 2024
@uweigand
Copy link
Member Author

Huh. Unfortunately, this still causes failures in the AMD GPU bots:
https://lab.llvm.org/buildbot/#/builders/193/builds/48380
I've reverted again for now. Need to look into this more.

uweigand added a commit that referenced this pull request Mar 15, 2024
Code in plugins-nextgen reading ELF files is currently hard-coded to
assume a 64-bit little-endian ELF format. Unfortunately, this assumption
is even embedded in the interface between GlobalHandler and Utils/ELF
routines, which use ELF64LE types.

To fix this, I've refactored the interface to use generic types, in
particular by using (a unique_ptr to) ObjectFile instead of
ELF64LEObjectFile, and ELFSymbolRef instead of ELF64LE::Sym.

This allows properly templating over multiple ELF format variants inside
Utils/ELF; specifically, this patch adds support for 64-bit big-endian
ELF files in addition to 64-bit little-endian files.
@uweigand
Copy link
Member Author

OK, found the bug. We need to translate a NULL ELFT::Sym pointer into a std::nullopt to indicate a symbol is not found. I've reapplied the PR with this bug fixed, and now all build bots finally remain green! Thanks for your patience in getting this resolved.

@uweigand uweigand deleted the openmp-plugin-elfbe-v2 branch March 15, 2024 18:02
uweigand added a commit that referenced this pull request Mar 15, 2024
The plugin was not getting built as the build_generic_elf64 macro
assumes the LLVM triple processor name matches the CMake processor name,
which is unfortunately not the case for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues causing
various test failures. Specifically, I've had to add the SystemZ target
to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED on
s390x-ibm-linux-gnu; all these tests were already marked as UNSUPPORTED
for x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu and are failing on
s390x for what seem to be the same reason.

In addition, this also requires support for BE ELF files in
plugins-nextgen: #85246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomptarget OpenMP offload runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants