-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Fix crash due to un-checked error in LVReaderHandler::handleArchive method #118951
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
Conversation
Fix crash due to un-checked error in LVReaderHandler::handleArchive method. Correction thanks to @CarlosAlbertoEnciso suggestion
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-debuginfo Author: None (aurelien35) ChangesFix crash due to un-checked error in LVReaderHandler::handleArchive method. Correction thanks to @CarlosAlbertoEnciso suggestion Full diff: https://github.com/llvm/llvm-project/pull/118951.diff 1 Files Affected:
diff --git a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
index 71750f3d114c11..7d64100c60c21a 100644
--- a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
@@ -88,6 +88,9 @@ Error LVReaderHandler::handleArchive(LVReaders &Readers, StringRef Filename,
Filename.str().c_str());
}
+ if (Err)
+ return createStringError(errorToErrorCode(std::move(Err)), "%s",
+ Filename.str().c_str());
return Error::success();
}
|
Suggested fix for this issue: #118753 |
@aurelien35 Can you add a test case that loads a library? Thanks |
Yes, I think this is a good idea, but I never worked on the LLVM tests suite. |
This is the directory for the You can check the tests for The test file can be in the
Additional information: filecheck, llvm testing. Any question, please do let me know. Happy to help. |
I've extended the llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp unit test with a unit test to load a library file. Without the merge request, it fails. I've made the .lib file using the "lib.exe" tool from msvc on the "llvm/unittests/DebugInfo/LogicalView/Inputs/test-codeview-msvc.o" file. I'm investigating further for other bugs concerning MSVC static libraries debug info loading. Do you know who can I contact about the MSVC CodeView information parsing specific topic? |
This was the starting documentation I used for the A presentation done by |
You can test this locally with the following command:git-clang-format --diff e9866d5d149706eac26f45bf0cab933c51d6d1cd 336844c32c43938866c3f315af745eddb1691292 --extensions cpp -- llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp View the diff from clang-format here.diff --git a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
index 7d64100c60..69513f2b98 100644
--- a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
@@ -90,7 +90,7 @@ Error LVReaderHandler::handleArchive(LVReaders &Readers, StringRef Filename,
if (Err)
return createStringError(errorToErrorCode(std::move(Err)), "%s",
- Filename.str().c_str());
+ Filename.str().c_str());
return Error::success();
}
diff --git a/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp b/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp
index c05114541d..7639f001e3 100644
--- a/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp
+++ b/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp
@@ -32,7 +32,8 @@ namespace {
const char *CodeViewClang = "test-codeview-clang.o";
const char *CodeViewMsvc = "test-codeview-msvc.o";
const char *CodeViewMsvcLib = "test-codeview-msvc.lib";
-const char *CodeViewMsvcLibContentName = "test-codeview-msvc.lib(test-codeview-msvc.o)";
+const char *CodeViewMsvcLibContentName =
+ "test-codeview-msvc.lib(test-codeview-msvc.o)";
const char *CodeViewPdbMsvc = "test-codeview-pdb-msvc.o";
// Helper function to get the first scope child from the given parent.
|
Quite interesting your approach to use a unit test to load a MSVC library. |
Would it be possible to add a README or something that explains how the file was created? |
@tstellar : I've added a README.md file which explains how I generated the .lib file However, I don't know how were generated the other binary files in this directory |
@aurelien35 I can check my notes about the steps used to generate the other binary files. |
@aurelien35 This is the information extracted from my notes. Source file:
Command line used to generate the binary files:
|
@CarlosAlbertoEnciso I've updated the README.md file with your notes |
@pogo59 Do you have any comments on this patch? Thanks |
@@ -193,6 +196,72 @@ void checkElementPropertiesMsvcCodeview(LVReader *Reader) { | |||
EXPECT_EQ(Lines->size(), 0x0eu); | |||
} | |||
|
|||
// Check the logical elements basic properties (MSVC library - Codeview). | |||
void checkElementPropertiesMsvcLibraryCodeview(LVReader *Reader) { | |||
LVScopeRoot *Root = Reader->getScopesRoot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that Root
is non-null
ASSERT_NE(Root, nullptr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this check in a separated patch.
LVScopeRoot *Root = Reader->getScopesRoot(); | ||
LVScopeCompileUnit *CompileUnit = | ||
static_cast<LVScopeCompileUnit *>(getFirstScopeChild(Root)); | ||
LVScopeFunction *Function = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same check here for CompileUnit
and Function
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this check in a separated patch.
const LVLocations *Ranges = Function->getRanges(); | ||
ASSERT_NE(Ranges, nullptr); | ||
ASSERT_EQ(Ranges->size(), 1u); | ||
LVLocations::const_iterator IterLocation = Ranges->begin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the iterators for end
ASSERT_NE(IterLocation, Ranges->end());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add this check in a separated patch.
No, it's fine. |
@aurelien35 The patch looks good. |
@CarlosAlbertoEnciso Thanks. What's next now? Should I do something or just wait for an admin to merge this patch? |
@aurelien35 Do you commit access? |
@CarlosAlbertoEnciso no, I don't have commit access |
@aurelien35 Did you added the suggested checks? I can commit for you. |
@aurelien35 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
@aurelien35 Committed the patch for you. |
Fix crash due to un-checked error in LVReaderHandler::handleArchive method.
Correction thanks to @CarlosAlbertoEnciso suggestion