File tree Expand file tree Collapse file tree 5 files changed +52
-6
lines changed Expand file tree Collapse file tree 5 files changed +52
-6
lines changed Original file line number Diff line number Diff line change @@ -1275,11 +1275,10 @@ static void foldIdenticalLiterals() {
1275
1275
static void addSynthenticMethnames () {
1276
1276
std::string &data = *make<std::string>();
1277
1277
llvm::raw_string_ostream os (data);
1278
- const int prefixLength = ObjCStubsSection::symbolPrefix.size ();
1279
1278
for (Symbol *sym : symtab->getSymbols ())
1280
1279
if (isa<Undefined>(sym))
1281
- if (sym-> getName (). starts_with ( ObjCStubsSection::symbolPrefix ))
1282
- os << sym-> getName (). drop_front (prefixLength ) << ' \0 ' ;
1280
+ if (ObjCStubsSection::isObjCStubSymbol (sym ))
1281
+ os << ObjCStubsSection::getMethname (sym ) << ' \0 ' ;
1283
1282
1284
1283
if (data.empty ())
1285
1284
return ;
Original file line number Diff line number Diff line change @@ -814,9 +814,19 @@ ObjCStubsSection::ObjCStubsSection()
814
814
: target->objcStubsSmallAlignment ;
815
815
}
816
816
817
+ bool ObjCStubsSection::isObjCStubSymbol (Symbol *sym) {
818
+ return sym->getName ().starts_with (symbolPrefix);
819
+ }
820
+
821
+ StringRef ObjCStubsSection::getMethname (Symbol *sym) {
822
+ assert (isObjCStubSymbol (sym) && " not an objc stub" );
823
+ auto name = sym->getName ();
824
+ StringRef methname = name.drop_front (symbolPrefix.size ());
825
+ return methname;
826
+ }
827
+
817
828
void ObjCStubsSection::addEntry (Symbol *sym) {
818
- assert (sym->getName ().starts_with (symbolPrefix) && " not an objc stub" );
819
- StringRef methname = sym->getName ().drop_front (symbolPrefix.size ());
829
+ StringRef methname = getMethname (sym);
820
830
offsets.push_back (
821
831
in.objcMethnameSection ->getStringOffset (methname).outSecOff );
822
832
Original file line number Diff line number Diff line change @@ -332,6 +332,8 @@ class ObjCStubsSection final : public SyntheticSection {
332
332
void setUp ();
333
333
334
334
static constexpr llvm::StringLiteral symbolPrefix = " _objc_msgSend$" ;
335
+ static bool isObjCStubSymbol (Symbol *sym);
336
+ static StringRef getMethname (Symbol *sym);
335
337
336
338
private:
337
339
std::vector<Defined *> symbols;
Original file line number Diff line number Diff line change @@ -736,8 +736,16 @@ void Writer::scanSymbols() {
736
736
dysym->getFile ()->refState =
737
737
std::max (dysym->getFile ()->refState , dysym->getRefState ());
738
738
} else if (isa<Undefined>(sym)) {
739
- if (sym->getName ().starts_with (ObjCStubsSection::symbolPrefix))
739
+ if (ObjCStubsSection::isObjCStubSymbol (sym)) {
740
+ // When -dead_strip is enabled, we don't want to emit any dead stubs.
741
+ // Although this stub symbol is yet undefined, addSym() was called
742
+ // during MarkLive.
743
+ if (config->deadStrip ) {
744
+ if (!sym->isLive ())
745
+ continue ;
746
+ }
740
747
in.objcStubs ->addEntry (sym);
748
+ }
741
749
}
742
750
}
743
751
Original file line number Diff line number Diff line change
1
+ # REQUIRES: aarch64
2
+
3
+ # RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o
4
+
5
+ # RUN: %lld -arch arm64 -lSystem -U _objc_msgSend -o %t.out %t.o
6
+ # RUN: llvm-nm %t.out | FileCheck %s
7
+ # RUN: %lld -arch arm64 -lSystem -U _objc_msgSend -dead_strip -o %t.out %t.o
8
+ # RUN: llvm-nm %t.out | FileCheck %s --check-prefix=DEAD
9
+
10
+ # CHECK: _foo
11
+ # CHECK: _objc_msgSend$length
12
+
13
+ # DEAD-NOT: _foo
14
+ # DEAD-NOT: _objc_msgSend$length
15
+
16
+ .section __TEXT,__text
17
+
18
+ .globl _foo
19
+ _foo:
20
+ bl _objc_msgSend$length
21
+ ret
22
+
23
+ .globl _main
24
+ _main:
25
+ ret
26
+
27
+ .subsections_via_symbols
You can’t perform that action at this time.
0 commit comments