aboutsummaryrefslogtreecommitdiff
path: root/lld/MachO
diff options
context:
space:
mode:
authorJez Ng <jezng@fb.com>2020-12-01 14:45:13 -0800
committerJez Ng <jezng@fb.com>2020-12-01 15:05:21 -0800
commitc7dbaec396ef98b8bc6acb7631d2919449986add (patch)
tree43fd320681ecef0a77fc99d06fa77a0725a51802 /lld/MachO
parent78f6498cdcdb5a7644b1c32615cfe2fdfd9c2545 (diff)
downloadllvm-project-c7dbaec396ef98b8bc6acb7631d2919449986add.tar.gz
[lld-macho] Add isCodeSection()
This is the same logic that ld64 uses to determine which sections contain functions. This was added so that we could determine which STABS entries should be N_FUN. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D92430
Diffstat (limited to 'lld/MachO')
-rw-r--r--lld/MachO/InputSection.cpp17
-rw-r--r--lld/MachO/InputSection.h2
-rw-r--r--lld/MachO/SyntheticSections.cpp4
3 files changed, 20 insertions, 3 deletions
diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index e164630159e2..80c263301f41 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -58,6 +58,23 @@ void InputSection::writeTo(uint8_t *buf) {
}
}
+bool macho::isCodeSection(InputSection *isec) {
+ uint32_t type = isec->flags & MachO::SECTION_TYPE;
+ if (type != S_REGULAR && type != S_COALESCED)
+ return false;
+
+ uint32_t attr = isec->flags & MachO::SECTION_ATTRIBUTES_USR;
+ if (attr == S_ATTR_PURE_INSTRUCTIONS)
+ return true;
+
+ if (isec->segname == segment_names::text)
+ return StringSwitch<bool>(isec->name)
+ .Cases("__textcoal_nt", "__StaticInit", true)
+ .Default(false);
+
+ return false;
+}
+
std::string lld::toString(const InputSection *isec) {
return (toString(isec->file) + ":(" + isec->name + ")").str();
}
diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 4ef8d84bc8a0..f405fd6cf6d3 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -76,6 +76,8 @@ public:
std::vector<Reloc> relocs;
};
+bool isCodeSection(InputSection *);
+
extern std::vector<InputSection *> inputSections;
} // namespace macho
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 6ba067bbc9e5..808d3594bfad 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -668,9 +668,7 @@ void SymtabSection::emitStabs() {
symStab.strx = stringTableSection.addString(defined->getName());
symStab.value = defined->getVA();
- // XXX is it right to assume that all symbols in __text are function
- // symbols?
- if (isec->name == "__text") {
+ if (isCodeSection(isec)) {
symStab.type = MachO::N_FUN;
stabs.emplace_back(std::move(symStab));
emitEndFunStab(defined);