Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[lld] Use --no-warnings flag to suppress --noinhibit-exec warnings #138056

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pranavk
Copy link
Contributor

@pranavk pranavk commented May 1, 2025

--noinhibit-exec is useful for debugging relocation errors for large binaries which usually emit tons and tons of linker warnings making the linking process prohibitively slow as it tries to construct useful messages by getting symbol and section names where error occurs. This is the main cause of linker slowdown that shows up in profiling such links using more than 90% of total link time.

These linker messages are not always needed. Use --no-warnings to speed up this linking process.

--noinhibit-exec is useful for debugging relocation errors for large
binaries which usually emit tons and tons of linker warnings making
the linking process very prohibitively slow as it tries to construct
useful messages by getting symbol and section names where error occurs.

These linker messages are not always needed. Use --no-warnings to
speed up this linking process.
@llvmbot
Copy link
Member

llvmbot commented May 1, 2025

@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Pranav Kant (pranavk)

Changes

--noinhibit-exec is useful for debugging relocation errors for large binaries which usually emit tons and tons of linker warnings making the linking process prohibitively slow as it tries to construct useful messages by getting symbol and section names where error occurs.

These linker messages are not always needed. Use --no-warnings to speed up this linking process.


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

3 Files Affected:

  • (modified) lld/ELF/Driver.cpp (+3-1)
  • (modified) lld/ELF/Relocations.cpp (+5-1)
  • (modified) lld/include/lld/Common/ErrorHandler.h (+1)
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 9d36071e1532f..42f65d81d657d 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -86,7 +86,9 @@ ELFSyncStream elf::Log(Ctx &ctx) { return {ctx, DiagLevel::Log}; }
 ELFSyncStream elf::Msg(Ctx &ctx) { return {ctx, DiagLevel::Msg}; }
 ELFSyncStream elf::Warn(Ctx &ctx) { return {ctx, DiagLevel::Warn}; }
 ELFSyncStream elf::Err(Ctx &ctx) {
-  return {ctx, ctx.arg.noinhibitExec ? DiagLevel::Warn : DiagLevel::Err};
+  if (ctx.arg.noinhibitExec)
+    return {ctx, ctx.e.suppressWarnings ? DiagLevel::None : DiagLevel::Warn};
+  return {ctx, DiagLevel::Err};
 }
 ELFSyncStream elf::ErrAlways(Ctx &ctx) { return {ctx, DiagLevel::Err}; }
 ELFSyncStream elf::Fatal(Ctx &ctx) { return {ctx, DiagLevel::Fatal}; }
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 277acb26987bc..e6f1078125a7e 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -87,8 +87,10 @@ static void printLocation(ELFSyncStream &s, InputSectionBase &sec,
 
 void elf::reportRangeError(Ctx &ctx, uint8_t *loc, const Relocation &rel,
                            const Twine &v, int64_t min, uint64_t max) {
-  ErrorPlace errPlace = getErrorPlace(ctx, loc);
   auto diag = Err(ctx);
+  if (diag.getDiagLevel() == DiagLevel::None)
+    return;
+  ErrorPlace errPlace = getErrorPlace(ctx, loc);
   diag << errPlace.loc << "relocation " << rel.type
        << " out of range: " << v.str() << " is not in [" << min << ", " << max
        << ']';
@@ -119,6 +121,8 @@ void elf::reportRangeError(Ctx &ctx, uint8_t *loc, const Relocation &rel,
 void elf::reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
                            const Symbol &sym, const Twine &msg) {
   auto diag = Err(ctx);
+  if (diag.getDiagLevel() == DiagLevel::None)
+    return;
   diag << getErrorPlace(ctx, loc).loc << msg << " is out of range: " << v
        << " is not in [" << llvm::minIntN(n) << ", " << llvm::maxIntN(n) << "]";
   if (!sym.getName().empty()) {
diff --git a/lld/include/lld/Common/ErrorHandler.h b/lld/include/lld/Common/ErrorHandler.h
index 4db1fec268d76..2ed666abef5dd 100644
--- a/lld/include/lld/Common/ErrorHandler.h
+++ b/lld/include/lld/Common/ErrorHandler.h
@@ -168,6 +168,7 @@ class SyncStream {
   ~SyncStream();
   StringRef str() { return os.str(); }
   uint64_t tell() { return os.tell(); }
+  DiagLevel getDiagLevel() { return level; }
 };
 
 [[noreturn]] void exitLld(int val);

@pranavk pranavk requested a review from smithp35 May 1, 2025 00:28
@smithp35
Copy link
Collaborator

smithp35 commented May 1, 2025

The title says [lld] Use --no-warnings flag to suppress --noinhibit-exec warnings but looking at the code and the description I think it should say [lld] Use --no-warnings flag to suppress --noinhibit-exec errors

I'd expect the --no-warnings to already suppress warnings that lld produces when --noinhibit-exec is used.

Personally, rather than overload --no-warnings to mean -no-errors but only when --noinhibit-exec is used I'd prefer to be explicit and add something like a --noinhibit-exec-errors option (really ought to be --no-noinhibit-exec-errors, but that it truly awful).

It will also be worth adding a test.

@pranavk
Copy link
Contributor Author

pranavk commented May 1, 2025

I'd expect the --no-warnings to already suppress warnings that lld produces when --noinhibit-exec is used.

I haven't checked that but my main motivation is to avoid calling getErrorPlace in reportRangeError() which is the expensive part I want to avoid in such links. So even if --no-warnings already doesn't warn in such cases, it would still call that expensive part.

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.

3 participants