Skip to content

[llvm-strip] Let llvm-strip continue on encountering an error #129531

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
Mar 7, 2025

Conversation

meltq
Copy link
Contributor

@meltq meltq commented Mar 3, 2025

This change means that llvm-strip no longer exits immediately upon encountering an error when modifying a file and will instead continue modifying the other inputs. Fixes #129412

@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-llvm-binary-utilities

Author: Tejas Vipin (meltq)

Changes

Lets tools that use llvm-objcopy continue with working on files on encountering an error by logging it instead of returning it early. This lets tools like llvm-strip function as expected while processing multiple files. Closes #129412


Full diff: https://github.com/llvm/llvm-project/pull/129531.diff

1 Files Affected:

  • (modified) llvm/tools/llvm-objcopy/llvm-objcopy.cpp (+5-2)
diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 7e708e309f207..e3d0ba5f8a0bb 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -247,14 +247,17 @@ int llvm_objcopy_main(int argc, char **argv, const llvm::ToolContext &) {
                           WithColor::error(errs(), ToolName));
     return 1;
   }
+
+  int ret = 0;
+
   for (ConfigManager &ConfigMgr : DriverConfig->CopyConfigs) {
     assert(!ConfigMgr.Common.ErrorCallback);
     ConfigMgr.Common.ErrorCallback = reportWarning;
     if (Error E = executeObjcopy(ConfigMgr)) {
       logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
-      return 1;
+      ret = 1;
     }
   }
 
-  return 0;
+  return ret;
 }

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

Thanks for the quick PR!

You need to add a test for the behaviour. You should add that test to llvm/test/tools/llvm-objcopy and show the following:

  1. That llvm-strip can successfully strip an object that appears later on the command-line after a bad object and returns 1 still.
  2. That llvm-strip emits an error for every bad object on the command-line.

You should also add a note in the LLVM release notes for llvm-objcopy for this fix (llvm/docs/release).

A couple of points about the commit title and description, since those end up as the commit message:

  1. Use "llvm-strip" in the title, since llvm-objcopy doesn't support multiple inputs.
  2. Bit of a nit-pick, but I'd say "Fixes XXXX" rather than "Closes XXXX" because it more clearly indicates that the issue is fixed.
  3. I think your description is a bit clunky, so we can improve that. Apart from anything else, there's no need to mention the source where this change was made. Try this:

This change means that llvm-strip no longer exits immediately upon encountering an error when modifying a file and will instead continue modifying the other inputs.

@meltq meltq changed the title [llvm-objcopy] Let llvm-objcopy continue on encountering an error [llvm-strip] Let llvm-strip continue on encountering an error Mar 4, 2025
@meltq
Copy link
Contributor Author

meltq commented Mar 4, 2025

Added the test, cleaned up the code and changed the title, description.

@meltq
Copy link
Contributor Author

meltq commented Mar 5, 2025

Made suggested changes.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

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

A couple of process points:

  1. Per the documented LLVM policy, please use fixup commits to make updates and avoid force pushes. Force pushing makes it difficult to review what has changed since the previous version of the PR, making reviewers' lives harder.
  2. Please don't click the "Resolve Conversation" button when you've addressed a request. As a reviewer, I use unresolved conversations to track what changes have been requested and then can review any changes against these conversations to see if the made changes were what were requested. See https://discourse.llvm.org/t/rfc-github-pr-resolve-conversation-button/73178 for more discussion.

Aside from that and one nit in the test, LGTM. Do you need help merging?

Comment on lines 23 to 25
- Name: .debugGlobal
Type: SHT_PROGBITS
Content: "00000000"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, please remove extra spaces.

Suggested change
- Name: .debugGlobal
Type: SHT_PROGBITS
Content: "00000000"
- Name: .debugGlobal
Type: SHT_PROGBITS
Content: "00000000"

@jh7370
Copy link
Collaborator

jh7370 commented Mar 6, 2025

Oh, one more thing, before this can be merged, you need to mark your email address as non-private in GitHub. From How to Submit a Patch:

After your PR is approved, ensure that:

  • The PR title and description describe the final changes. These will be used as the title and message of the final squashed commit. The titles and messages of commits in the PR will not be used.
  • You have set a valid email address in your GitHub account, see Email Addresses.

This change means that llvm-strip no longer exits immediately upon
encountering an error when modifying a file and will instead continue
modifying the other inputs.
@meltq
Copy link
Contributor Author

meltq commented Mar 6, 2025

Addressed Nit. From my understanding, all commits need to be merged at the end so I rebased and force pushed (unless I was wrong?)
Additionally, my email address should be public now. And I would appreciate you merging.

@jh7370
Copy link
Collaborator

jh7370 commented Mar 6, 2025

Addressed Nit. From my understanding, all commits need to be merged at the end so I rebased and force pushed (unless I was wrong?)

You're right in that the final commit that lands in main should be a single distinct commit (so all fixups should be merged). However, the default merge option we use in GitHub is "Squash and Merge" which squashes the commits into a single commit and then rebases it on main, before pushing, so there's no need to do it manually.

Additionally, my email address should be public now. And I would appreciate you merging.

Noted. I'll let the pre-merge checks finish before doing the merge.

@jh7370 jh7370 merged commit bd5f29c into llvm:main Mar 7, 2025
12 checks passed
@meltq meltq deleted the strip branch March 7, 2025 08:36
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…29531)

This change means that llvm-strip no longer exits immediately upon
encountering an error when modifying a file and will instead continue
modifying the other inputs. Fixes llvm#129412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[llvm-strip] llvm-strip --strip-unneeded cannot would stop stripping if it encounters failure for one file
3 participants