[PATCH] D144471: [ELF] Prohibit icf=safe warning from being fatal

Marco Elver via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 21 03:56:58 PST 2023


melver created this revision.
melver added reviewers: MaskRay, jhenderson.
Herald added subscribers: arichardson, emaste.
Herald added a project: All.
melver requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Many projects compile with fatal linker warnings. The fact that icf=safe
has limitations with object files created by ld -r or objcopy limits
such projects from either (a) using --fatal-warnings, or (b) using ld or
objcopy produced dependencies.

Arguably, users that use ld/objcopy should be aware of icf=safe's
limitations, but should never affect _consumers_ of dependencies created
in this way. An example is a library that must internalize symbols to
ship and safely link into other targets.

Not being able to apply ICF to such a library should not be a
dealbreaker for projects that employ --fatal-warnings. The rest of the
project's object files can still employ ICF, while incompatible object
files are skipped with the warning.

Never treat icf=safe warnings as fatal.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144471

Files:
  lld/Common/ErrorHandler.cpp
  lld/ELF/InputFiles.cpp
  lld/include/lld/Common/ErrorHandler.h


Index: lld/include/lld/Common/ErrorHandler.h
===================================================================
--- lld/include/lld/Common/ErrorHandler.h
+++ lld/include/lld/Common/ErrorHandler.h
@@ -112,7 +112,7 @@
   [[noreturn]] void fatal(const Twine &msg);
   void log(const Twine &msg);
   void message(const Twine &msg, llvm::raw_ostream &s);
-  void warn(const Twine &msg);
+  void warn(const Twine &msg, bool neverFatal = false);
 
   raw_ostream &outs();
   raw_ostream &errs();
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -713,12 +713,13 @@
         if (sec.sh_link != 0)
           this->addrsigSec = &sec;
         else if (config->icf == ICFLevel::Safe)
-          warn(toString(this) +
-               ": --icf=safe conservatively ignores "
-               "SHT_LLVM_ADDRSIG [index " +
-               Twine(i) +
-               "] with sh_link=0 "
-               "(likely created using objcopy or ld -r)");
+          errorHandler().warn(toString(this) +
+                                  ": --icf=safe conservatively ignores "
+                                  "SHT_LLVM_ADDRSIG [index " +
+                                  Twine(i) +
+                                  "] with sh_link=0 "
+                                  "(likely created using objcopy or ld -r)",
+                              /*neverFatal=*/true);
       }
       this->sections[i] = &InputSection::discarded;
       continue;
Index: lld/Common/ErrorHandler.cpp
===================================================================
--- lld/Common/ErrorHandler.cpp
+++ lld/Common/ErrorHandler.cpp
@@ -236,8 +236,8 @@
   s.flush();
 }
 
-void ErrorHandler::warn(const Twine &msg) {
-  if (fatalWarnings) {
+void ErrorHandler::warn(const Twine &msg, bool neverFatal) {
+  if (!neverFatal && fatalWarnings) {
     error(msg);
     return;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144471.499106.patch
Type: text/x-patch
Size: 1944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/08687390/attachment.bin>


More information about the llvm-commits mailing list