Skip to content

Commit

Permalink
[lld][macho][NFC] Add specific namespace scope for objc symbol names (#…
Browse files Browse the repository at this point in the history
…83618)

Move symbol names from directly under `objc` scope to
`objc::symbol_names`.
Ex: `objc::klass` -> `objc::symbol_names::klass`

Co-authored-by: Alex B <alexborcan@meta.com>
  • Loading branch information
alx32 and Alex B committed Mar 1, 2024
1 parent f7a15e0 commit 7a2d934
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
}
} else if (isCommandLineLoad && config->forceLoadObjC) {
for (const object::Archive::Symbol &sym : file->getArchive().symbols())
if (sym.getName().starts_with(objc::klass))
if (sym.getName().starts_with(objc::symbol_names::klass))
file->fetch(sym);

// TODO: no need to look for ObjC sections for a given archive member if
Expand Down Expand Up @@ -395,7 +395,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
if ((isa<ObjFile>(newFile) || isa<BitcodeFile>(newFile)) && newFile->lazy &&
config->forceLoadObjC) {
for (Symbol *sym : newFile->symbols)
if (sym && sym->getName().starts_with(objc::klass)) {
if (sym && sym->getName().starts_with(objc::symbol_names::klass)) {
extract(*newFile, "-ObjC");
break;
}
Expand Down
8 changes: 4 additions & 4 deletions lld/MachO/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,14 +1921,14 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
case EncodeKind::ObjectiveCClass:
// XXX ld64 only creates these symbols when -ObjC is passed in. We may
// want to emulate that.
addSymbol(*symbol, objc::klass + symbol->getName());
addSymbol(*symbol, objc::metaclass + symbol->getName());
addSymbol(*symbol, objc::symbol_names::klass + symbol->getName());
addSymbol(*symbol, objc::symbol_names::metaclass + symbol->getName());
break;
case EncodeKind::ObjectiveCClassEHType:
addSymbol(*symbol, objc::ehtype + symbol->getName());
addSymbol(*symbol, objc::symbol_names::ehtype + symbol->getName());
break;
case EncodeKind::ObjectiveCInstanceVariable:
addSymbol(*symbol, objc::ivar + symbol->getName());
addSymbol(*symbol, objc::symbol_names::ivar + symbol->getName());
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions lld/MachO/ObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ namespace lld::macho {

namespace objc {

namespace symbol_names {
constexpr const char klass[] = "_OBJC_CLASS_$_";
constexpr const char metaclass[] = "_OBJC_METACLASS_$_";
constexpr const char ehtype[] = "_OBJC_EHTYPE_$_";
constexpr const char ivar[] = "_OBJC_IVAR_$_";
} // namespace symbol_names

// Check for duplicate method names within related categories / classes.
void checkCategories();
Expand Down

0 comments on commit 7a2d934

Please sign in to comment.