[lld] d82422f - [ELF] Remove errorOrWarn

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 09:37:44 PST 2024


Author: Fangrui Song
Date: 2024-11-15T09:37:38-08:00
New Revision: d82422f69c573d051cf08d6d267b619197aab363

URL: https://github.com/llvm/llvm-project/commit/d82422f69c573d051cf08d6d267b619197aab363
DIFF: https://github.com/llvm/llvm-project/commit/d82422f69c573d051cf08d6d267b619197aab363.diff

LOG: [ELF] Remove errorOrWarn

Added: 
    

Modified: 
    lld/ELF/Config.h
    lld/ELF/Driver.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 56db089ec876b4..227f87e2dd01b9 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -676,10 +676,7 @@ static inline ArrayRef<VersionDefinition> namedVersionDefs(Ctx &ctx) {
 
 void errorOrWarn(const Twine &msg);
 
-static inline void internalLinkerError(StringRef loc, const Twine &msg) {
-  errorOrWarn(loc + "internal linker error: " + msg + "\n" +
-              llvm::getBugReportMsg());
-}
+void internalLinkerError(StringRef loc, const Twine &msg);
 
 struct ELFSyncStream : SyncStream {
   Ctx &ctx;

diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index a812b53ce1afbc..b108ce3aa7035a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -84,13 +84,6 @@ Ctx elf::ctx;
 static void setConfigs(Ctx &ctx, opt::InputArgList &args);
 static void readConfigs(Ctx &ctx, opt::InputArgList &args);
 
-void elf::errorOrWarn(const Twine &msg) {
-  if (ctx.arg.noinhibitExec)
-    Warn(ctx) << msg;
-  else
-    ErrAlways(ctx) << msg;
-}
-
 ELFSyncStream elf::Log(Ctx &ctx) { return {ctx, DiagLevel::Log}; }
 ELFSyncStream elf::Warn(Ctx &ctx) { return {ctx, DiagLevel::Warn}; }
 ELFSyncStream elf::Err(Ctx &ctx) {
@@ -100,6 +93,11 @@ ELFSyncStream elf::ErrAlways(Ctx &ctx) { return {ctx, DiagLevel::Err}; }
 ELFSyncStream elf::Fatal(Ctx &ctx) { return {ctx, DiagLevel::Fatal}; }
 uint64_t elf::errCount(Ctx &ctx) { return ctx.errHandler->errorCount; }
 
+void elf::internalLinkerError(StringRef loc, const Twine &msg) {
+  ELFSyncStream(ctx, DiagLevel::Err) << "internal linker error: " << msg << '\n'
+                                     << llvm::getBugReportMsg();
+}
+
 Ctx::Ctx() : driver(*this) {}
 
 void Ctx::reset() {

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 82b4491b1c59ed..16f9a1514b06b2 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1822,10 +1822,11 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
       ctx.in.iplt->addSymbols();
 
     if (ctx.arg.unresolvedSymbolsInShlib != UnresolvedPolicy::Ignore) {
-      auto diagnose =
-          ctx.arg.unresolvedSymbolsInShlib == UnresolvedPolicy::ReportError
-              ? errorOrWarn
-              : warn;
+      auto diag =
+          ctx.arg.unresolvedSymbolsInShlib == UnresolvedPolicy::ReportError &&
+                  !ctx.arg.noinhibitExec
+              ? DiagLevel::Err
+              : DiagLevel::Warn;
       // Error on undefined symbols in a shared object, if all of its DT_NEEDED
       // entries are seen. These cases would otherwise lead to runtime errors
       // reported by the dynamic linker.
@@ -1850,14 +1851,14 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
           if (sym->dsoDefined)
             continue;
           if (sym->isUndefined() && !sym->isWeak()) {
-            diagnose("undefined reference: " + toString(*sym) +
-                     "\n>>> referenced by " + toString(file) +
-                     " (disallowed by --no-allow-shlib-undefined)");
+            ELFSyncStream(ctx, diag)
+                << "undefined reference: " << sym << "\n>>> referenced by "
+                << file << " (disallowed by --no-allow-shlib-undefined)";
           } else if (sym->isDefined() &&
                      sym->computeBinding(ctx) == STB_LOCAL) {
-            diagnose("non-exported symbol '" + toString(*sym) + "' in '" +
-                     toString(sym->file) + "' is referenced by DSO '" +
-                     toString(file) + "'");
+            ELFSyncStream(ctx, diag)
+                << "non-exported symbol '" << sym << "' in '" << sym->file
+                << "' is referenced by DSO '" << file << "'";
           }
         }
       }


        


More information about the llvm-commits mailing list