+2021-02-04  Alan Modra  <amodra@gmail.com>
+
+       PR 27311
+       * elflink.c (elf_link_add_object_symbols): Don't pull in as-needed
+       libraries for IR references on pass over libraries after LTO
+       recompilation.
+
 2021-02-03  Alan Modra  <amodra@gmail.com>
 
        PR 27311
 
                   && h->ref_regular_nonweak)
                  || (old_bfd != NULL
                      && (old_bfd->flags & BFD_PLUGIN) != 0
+                     && !info->lto_all_symbols_read
                      && bind != STB_WEAK)
                  || (h->ref_dynamic_nonweak
                      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
 
+2021-02-04  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/ld-plugin/pr27311d.c: New test.
+       * testsuite/ld-plugin/lto.exp: Rename pr27311 to pr27311-1, compile
+       and link new test as pr27311-2.
+
 2021-02-03  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-ifunc/ifunc.exp (libpr16467b.so, libpr16467bn.so):
 
   [list {pr27311c.o} \
    {} {-flto} \
    {pr27311c.c} {} {} {c}] \
-  [list {pr27311} \
+  [list {pr27311d.o} \
+   {} {-flto} \
+   {pr27311d.c} {} {} {c}] \
+  [list {pr27311-1} \
    {tmpdir/pr27311c.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
-   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311}] \
+   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-1}] \
+  [list {pr27311-2} \
+   {tmpdir/pr27311d.o -Wl,--no-as-needed,--rpath-link=. tmpdir/pr27311b.so} {} \
+   {dummy.c} {{readelf {--dyn-syms --wide} pr27311.d}} {pr27311-2}] \
 ]
 
 # PR 14918 checks that libgcc is not spuriously included in a shared link of
 
--- /dev/null
+__attribute__((visibility("hidden"))) void inlib1(void) {}
+int main()
+{
+  return 0;
+}