ports/devel/llvm/13/patches/patch-lld_ELF_InputFiles_cpp

83 lines
3 KiB
Text

- lld: do not report undefined weak references in shared libraries
https://github.com/llvm/llvm-project/commit/52bfd2c1ccd86ff813ee6df5a6700690acdd
- add .gnu.warning.SYMBOL support to ld.lld(1)
Index: lld/ELF/InputFiles.cpp
--- lld/ELF/InputFiles.cpp.orig
+++ lld/ELF/InputFiles.cpp
@@ -52,6 +52,8 @@ std::vector<SharedFile *> elf::sharedFiles;
std::unique_ptr<TarWriter> elf::tar;
+DenseMap<StringRef, StringRef> elf::gnuWarnings;
+
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
std::string lld::toString(const InputFile *f) {
if (!f)
@@ -66,6 +68,17 @@ std::string lld::toString(const InputFile *f) {
return f->toStringCache;
}
+// .gnu.warning.SYMBOL are treated as warning symbols for the given symbol
+void lld::parseGNUWarning(StringRef name, ArrayRef<char> data, size_t size) {
+ if (!name.empty() && name.startswith(".gnu.warning.")) {
+ StringRef wsym = name.substr(13);
+ StringRef s(data.begin());
+ StringRef wng(s.substr(0, size));
+ symtab->insert(wsym)->gwarn = true;
+ gnuWarnings.insert({wsym, wng});
+ }
+}
+
static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {
unsigned char size;
unsigned char endian;
@@ -647,6 +660,14 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComd
case SHT_RELA:
case SHT_NULL:
break;
+ case SHT_PROGBITS: {
+ this->sections[i] = createInputSection(sec);
+ StringRef name = CHECK(obj.getSectionName(sec, this->sectionStringTable), this);
+ ArrayRef<char> data =
+ CHECK(obj.template getSectionContentsAsArray<char>(sec), this);
+ parseGNUWarning(name, data, sec.sh_size);
+ }
+ break;
default:
this->sections[i] = createInputSection(sec);
}
@@ -1450,6 +1471,9 @@ template <class ELFT> void SharedFile::parse() {
const ELFFile<ELFT> obj = this->getObj<ELFT>();
ArrayRef<Elf_Shdr> sections = CHECK(obj.sections(), this);
+ StringRef sectionStringTable =
+ CHECK(obj.getSectionStringTable(sections), this);
+
const Elf_Shdr *versymSec = nullptr;
const Elf_Shdr *verdefSec = nullptr;
const Elf_Shdr *verneedSec = nullptr;
@@ -1472,7 +1496,14 @@ template <class ELFT> void SharedFile::parse() {
case SHT_GNU_verneed:
verneedSec = &sec;
break;
+ case SHT_PROGBITS: {
+ StringRef name = CHECK(obj.getSectionName(sec, sectionStringTable), this);
+ ArrayRef<char> data =
+ CHECK(obj.template getSectionContentsAsArray<char>(sec), this);
+ parseGNUWarning(name, data, sec.sh_size);
+ break;
}
+ }
}
if (versymSec && numELFSyms == 0) {
@@ -1567,7 +1598,7 @@ template <class ELFT> void SharedFile::parse() {
Symbol *s = symtab->addSymbol(
Undefined{this, name, sym.getBinding(), sym.st_other, sym.getType()});
s->exportDynamic = true;
- if (s->isUndefined() && !s->isWeak() &&
+ if (s->isUndefined() && sym.getBinding() != STB_WEAK &&
config->unresolvedSymbolsInShlib != UnresolvedPolicy::Ignore)
requiredSymbols.push_back(s);
continue;