Skip to content

Commit 95d49c6

Browse files
author
Alex B
committed
Address feedback nr.1
1 parent 9537ec3 commit 95d49c6

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

lld/MachO/ConcatOutputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TextOutputSection : public ConcatOutputSection {
7272
void finalizeContents() override {}
7373
void finalize() override;
7474
bool needsThunks() const;
75-
const std::vector<ConcatInputSection *> &getThunks() const { return thunks; }
75+
ArrayRef<ConcatInputSection *> getThunks() const { return thunks; }
7676
void writeTo(uint8_t *buf) const override;
7777

7878
static bool classof(const OutputSection *sec) {

lld/MachO/MapFile.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,13 @@ static uint64_t getSymSizeForMap(Defined *sym) {
165165
// This approach creates a new (temporary) vector which is not ideal but the
166166
// ideal approach leads to a lot of code duplication.
167167
static std::vector<ConcatInputSection *>
168-
mergeOrderedInputs(const std::vector<ConcatInputSection *> &inputs1,
169-
const std::vector<ConcatInputSection *> &inputs2) {
170-
std::vector<ConcatInputSection *> vec;
171-
size_t i = 0, ie = inputs1.size();
172-
size_t t = 0, te = inputs2.size();
173-
while (i < ie || t < te) {
174-
while (i < ie &&
175-
(t == te || inputs1[i]->outSecOff <= inputs2[t]->outSecOff)) {
176-
vec.push_back(inputs1[i++]);
177-
}
178-
while (t < te &&
179-
(i == ie || inputs2[t]->outSecOff < inputs1[i]->outSecOff)) {
180-
vec.push_back(inputs2[t++]);
181-
}
182-
}
168+
mergeOrderedInputs(ArrayRef<ConcatInputSection *> inputs1,
169+
ArrayRef<ConcatInputSection *> inputs2) {
170+
std::vector<ConcatInputSection *> vec(inputs1.size() + inputs2.size());
171+
std::merge(inputs1.begin(), inputs1.end(), inputs2.begin(), inputs2.end(),
172+
vec.begin(), [](ConcatInputSection *a, ConcatInputSection *b) {
173+
return a->outSecOff < b->outSecOff;
174+
});
183175
return vec;
184176
}
185177

lld/test/MachO/arm64-thunks.s

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,34 @@
1818
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t/thunk | FileCheck %s
1919

2020
## Check that the thunks appear in the map file and that everything is sorted by address
21-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _b
22-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _c
23-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _d.thunk.0
24-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _e.thunk.0
25-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _f.thunk.0
26-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _g.thunk.0
27-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _h.thunk.0
28-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] ___nan.thunk.0
29-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _d
30-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _e
31-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _f
32-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _g
33-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _a.thunk.0
34-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _b.thunk.0
35-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _h
36-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _main
37-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _c.thunk.0
38-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _d.thunk.1
39-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _e.thunk.1
40-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _f.thunk.1
41-
# MAP: [[0x[0-9A-Fa-f]+]] 0x[0-9A-Fa-f]+ \[[0-9]+\] _z
21+
# Because of the `.space` instructions, there will end up being a lot of dead symbols in the linker map
22+
# so generate a version of the linker map without dead symbols.
23+
# RUN: awk '/# Dead Stripped Symbols:/ {exit} {print}' %t/thunk.map > %t/thunk_no_dead_syms.map
24+
25+
# RUN: FileCheck %s --input-file %t/thunk_no_dead_syms.map --check-prefix=MAP
26+
27+
# MAP: [[ADDR1:0x[0-9A-Fa-f]+]] {{.*}} _b
28+
# MAP-NEXT: [[ADDR2:0x[0-9A-Fa-f]+]] {{.*}} _c
29+
# MAP-NEXT: [[ADDR3:0x[0-9A-Fa-f]+]] {{.*}} _d.thunk.0
30+
# MAP-NEXT: [[ADDR4:0x[0-9A-Fa-f]+]] {{.*}} _e.thunk.0
31+
# MAP-NEXT: [[ADDR5:0x[0-9A-Fa-f]+]] {{.*}} _f.thunk.0
32+
# MAP-NEXT: [[ADDR6:0x[0-9A-Fa-f]+]] {{.*}} _g.thunk.0
33+
# MAP-NEXT: [[ADDR7:0x[0-9A-Fa-f]+]] {{.*}} _h.thunk.0
34+
# MAP-NEXT: [[ADDR8:0x[0-9A-Fa-f]+]] {{.*}} ___nan.thunk.0
35+
# MAP-NEXT: [[ADDR9:0x[0-9A-Fa-f]+]] {{.*}} _d
36+
# MAP-NEXT: [[ADDR10:0x[0-9A-Fa-f]+]] {{.*}} _e
37+
# MAP-NEXT: [[ADDR11:0x[0-9A-Fa-f]+]] {{.*}} _f
38+
# MAP-NEXT: [[ADDR12:0x[0-9A-Fa-f]+]] {{.*}} _g
39+
# MAP-NEXT: [[ADDR13:0x[0-9A-Fa-f]+]] {{.*}} _a.thunk.0
40+
# MAP-NEXT: [[ADDR14:0x[0-9A-Fa-f]+]] {{.*}} _b.thunk.0
41+
# MAP-NEXT: [[ADDR15:0x[0-9A-Fa-f]+]] {{.*}} _h
42+
# MAP-NEXT: [[ADDR16:0x[0-9A-Fa-f]+]] {{.*}} _main
43+
# MAP-NEXT: [[ADDR17:0x[0-9A-Fa-f]+]] {{.*}} _c.thunk.0
44+
# MAP-NEXT: [[ADDR18:0x[0-9A-Fa-f]+]] {{.*}} _d.thunk.1
45+
# MAP-NEXT: [[ADDR19:0x[0-9A-Fa-f]+]] {{.*}} _e.thunk.1
46+
# MAP-NEXT: [[ADDR20:0x[0-9A-Fa-f]+]] {{.*}} _f.thunk.1
47+
# MAP-NEXT: [[ADDR21:0x[0-9A-Fa-f]+]] {{.*}} _z
48+
4249

4350
# CHECK: Disassembly of section __TEXT,__text:
4451

0 commit comments

Comments
 (0)