This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objdump] Change printSymbolVersionDependency to use ELFFile API
ClosedPublic

Authored by MaskRay on Sep 13 2022, 12:12 AM.

Details

Summary

When .gnu.version_r is empty (allowed by readelf but warned by objdump),
llvm-objdump -p may decode the next section as .gnu.version_r and may crash due
to out-of-bounds C string reference. ELFFile<ELFT>::getVersionDependencies
handles 0-entry .gnu.version_r gracefully. Just use it.

Fix https://github.com/llvm/llvm-project/issues/57707

Diff Detail

Event Timeline

MaskRay created this revision.Sep 13 2022, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 12:12 AM
MaskRay requested review of this revision.Sep 13 2022, 12:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 12:12 AM
jhenderson added inline comments.Sep 13 2022, 1:06 AM
llvm/include/llvm/Object/ELF.h
1041

Should this be a separate patch?

llvm/test/tools/llvm-objdump/ELF/verneed-invalid.test
2

Similarly, this test seems unrelated to the commit message?

llvm/tools/llvm-objdump/ELFDump.cpp
301–306

Nit: this local variable seems a little bit unnecessary?

352–356

These variables are only used in the else part now. Could we move them?

MaskRay added inline comments.Sep 13 2022, 10:58 AM
llvm/include/llvm/Object/ELF.h
1041

Without this change llvm-objdump -p output may contain \0 separated strings, which are incorrect.

The only other use llvm/tools/llvm-readobj/ELFDumper.cpp:4706 avoids the problem by using VN.File.data().

llvm/test/tools/llvm-objdump/ELF/verneed-invalid.test
2

I need a file to test reportWarning(toString(V.takeError()), FileName);

The change is like rewriting an existing functionality. Personally I think the needed tests should be like as if we do not have the functionality yet.

llvm/tools/llvm-objdump/ELFDump.cpp
301–306

It avoids repeated outs() call at the cost of one extra line. I think it is worthwhile.

352–356

They can but they aren't so related to this change. We can rewrite printSymbolVersionDefinition to use the llvm/lib/Object API as well then these variables can go away with that change.

The patch looks good to me. I have tested it in yocto world builds, it fixes the problem and there are no new regressions.

jhenderson accepted this revision.Sep 14 2022, 12:04 AM

Looks good, thanks!

llvm/test/tools/llvm-objdump/ELF/verneed-invalid.test
2

The change is like rewriting an existing functionality. Personally I think the needed tests should be like as if we do not have the functionality yet.

Agreed. If anything, I'd have added this as a prerequisite patch, but it's fine as-is. Thanks!

llvm/tools/llvm-objdump/ELFDump.cpp
352–356

Sounds reasonable.

This revision is now accepted and ready to land.Sep 14 2022, 12:04 AM

Thanks. I'll split verneed-invalid.test

MaskRay marked 2 inline comments as done.Sep 14 2022, 12:28 PM