Skip to content

[Libomptarget] Move ELF symbol extraction to the ELF utility #74717

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

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Dec 7, 2023

Summary:
We shouldn't have the format specific ELF handling in the generic plugin
manager. This patch moves that out of the implementation and into the
ELF utilities. This patch changes the SHT_NOBITS case to be a hard
error, which should be correct as the existing use already seemed to
return an error if the result was a null pointer.

This also uses a const_cast, which is bad practice. However,
rebuilding the constness of all of this would be a massive overhaul,
and this matches the previous behaviour (We would take a pointer to the
image that is most likely read-only in the ELF).

Summary:
We shouldn't have the format specific ELF handling in the generic plugin
manager. This patch moves that out of the implementation and into the
ELF utilities. This patch changes the SHT_NOBITS case to be a hard
error, which should be correct as the existing use already seemed to
return an error if the result was a null pointer.

This also uses a `const_cast`, which is bad practice. However,
rebuilding the `constness` of all of this would be a massive overhaul,
and this matches the previous behaviour (We would take a pointer to the
image that is most likely read-only in the ELF).
@llvmbot llvmbot added the openmp:libomptarget OpenMP offload runtime label Dec 7, 2023
// A section with SHT_NOBITS occupies no space in the file and has no offset.
if (Section->sh_type == ELF::SHT_NOBITS)
return createError(
"invalid sh_type for symbol lookup, cannot be SHT_NOBITS");
Copy link
Member

Choose a reason for hiding this comment

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

Why is this en error now? The ELF clearly has the symbol and for things like Size estimation we can use it just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure what the original intention was, as far as I could tell it would hit this error because there was a check for nullptr right after where we would look this up. That being said, even though we can check size and it exists, it still had no data associated with it so it seems kind of weird. If you want to look up a symbol you can use the other ELF Symbol lookup so that's my understanding.

Copy link
Member

Choose a reason for hiding this comment

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

Now you can't call getMetadataFromImage anymore to get the size. I thought that could be useful. Anyway, we can add some new API or extend the other one if we need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's freely available with Sym->st_size. We could make a nicer looking helper if that's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially we could make getMetadataFromImage do the nullptr handling. I just think that it's correct to have the function that gets the associated data to error if no such data exists.

@jhuber6 jhuber6 requested a review from jdoerfert December 13, 2023 16:28
Copy link
Member

@jdoerfert jdoerfert left a comment

Choose a reason for hiding this comment

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

LG

@jhuber6 jhuber6 merged commit 0ab663d into llvm:main Dec 14, 2023
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