D59275 added the following clause to Symbol::includeInDynsym()
if (isUndefWeak() && Config->Pie && SharedFiles.empty()) return false;
It seems we don't have to differentiate non-PIE from PIE, thus we can
generalize it to weak undefined symbols in any static executable:
if (!Config->Shared && isUndefWeak() && SharedFiles.empty()) return false;
Note !Config->Shared && isUndefWeak() is used to decide whether a
relocation which is not a constant at link time should resolve to 0.
This patch adjusts the order of clauses to make the code simpler.
ld.bfd has complex and architecture-varying rules. We try to provide
reasonable semantics to exclude some weak undefined symbols but not be
too smart. Future improvement may include the refinement of
ExportDynamic assignment.
In the updated tests, weak-undef-rw.s is folded into
weak-undef-exported.s as they are checking the same thing except that
the former checks a writable section.