[ELF] --warn-backrefs: don't warn if -u/--export-dynamic-symbol
authorFangrui Song <maskray@google.com>
Tue, 7 Apr 2020 04:12:19 +0000 (21:12 -0700)
committerFangrui Song <maskray@google.com>
Wed, 8 Apr 2020 16:33:22 +0000 (09:33 -0700)
Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D77630

lld/ELF/Driver.cpp
lld/test/ELF/warn-backrefs.s

index c90ac58..2aeeb84 100644 (file)
@@ -1448,6 +1448,10 @@ static void handleUndefined(Symbol *sym) {
   // eliminate it. Mark the symbol as "used" to prevent it.
   sym->isUsedInRegularObj = true;
 
+  // GNU linkers allow -u foo -ldef -lref. We should not treat it as a backward
+  // reference.
+  backwardReferences.erase(sym);
+
   if (sym->isLazy())
     sym->fetch();
 }
index 3d6bcb9..5dec458 100644 (file)
 ## --warn-backrefs does not warn.
 # RUN: ld.lld --fatal-warnings --warn-backrefs %t2.a %t1.o %t2.so %t2.a -o /dev/null
 
+## In GNU linkers, -u does not make a backward reference.
+# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null
+
+## In GNU gold, --export-dynamic-symbol does not make a backward reference.
+# RUN: ld.lld --fatal-warnings --warn-backrefs --export-dynamic-symbol foo %t2.a %t1.o -o /dev/null
+
 .globl _start, foo
 _start:
   call foo