Skip to content

Commit daf1464

Browse files
authored
Merge branch 'llvm:main' into renaming-bug-reports
2 parents df731e3 + 0462dfe commit daf1464

File tree

7 files changed

+142
-37
lines changed

7 files changed

+142
-37
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,28 +2554,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
25542554
e.symbolName = symtab.mangleMaybe(e.sym);
25552555
}
25562556

2557-
// Add weak aliases. Weak aliases is a mechanism to give remaining
2558-
// undefined symbols final chance to be resolved successfully.
2559-
for (auto pair : symtab.alternateNames) {
2560-
StringRef from = pair.first;
2561-
StringRef to = pair.second;
2562-
Symbol *sym = symtab.find(from);
2563-
if (!sym)
2564-
continue;
2565-
if (auto *u = dyn_cast<Undefined>(sym)) {
2566-
if (u->weakAlias) {
2567-
// On ARM64EC, anti-dependency aliases are treated as undefined
2568-
// symbols unless a demangled symbol aliases a defined one, which
2569-
// is part of the implementation.
2570-
if (!symtab.isEC() || !u->isAntiDep)
2571-
continue;
2572-
if (!isa<Undefined>(u->weakAlias) &&
2573-
!isArm64ECMangledFunctionName(u->getName()))
2574-
continue;
2575-
}
2576-
u->setWeakAlias(symtab.addUndefined(to));
2577-
}
2578-
}
2557+
symtab.resolveAlternateNames();
25792558
});
25802559

25812560
ctx.forEachActiveSymtab([&](SymbolTable &symtab) {

lld/COFF/PDB.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,12 @@ static pdb::BulkPublic createPublic(COFFLinkerContext &ctx, Defined *def) {
11351135
pub.setFlags(flags);
11361136

11371137
OutputSection *os = ctx.getOutputSection(def->getChunk());
1138-
assert(os && "all publics should be in final image");
1139-
pub.Offset = def->getRVA() - os->getRVA();
1140-
pub.Segment = os->sectionIndex;
1138+
assert((os || !def->getChunk()->getSize()) &&
1139+
"all publics should be in final image");
1140+
if (os) {
1141+
pub.Offset = def->getRVA() - os->getRVA();
1142+
pub.Segment = os->sectionIndex;
1143+
}
11411144
return pub;
11421145
}
11431146

lld/COFF/SymbolTable.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,31 @@ void SymbolTable::parseAlternateName(StringRef s) {
13441344
alternateNames.insert(it, std::make_pair(from, to));
13451345
}
13461346

1347+
void SymbolTable::resolveAlternateNames() {
1348+
// Add weak aliases. Weak aliases is a mechanism to give remaining
1349+
// undefined symbols final chance to be resolved successfully.
1350+
for (auto pair : alternateNames) {
1351+
StringRef from = pair.first;
1352+
StringRef to = pair.second;
1353+
Symbol *sym = find(from);
1354+
if (!sym)
1355+
continue;
1356+
if (auto *u = dyn_cast<Undefined>(sym)) {
1357+
if (u->weakAlias) {
1358+
// On ARM64EC, anti-dependency aliases are treated as undefined
1359+
// symbols unless a demangled symbol aliases a defined one, which
1360+
// is part of the implementation.
1361+
if (!isEC() || !u->isAntiDep)
1362+
continue;
1363+
if (!isa<Undefined>(u->weakAlias) &&
1364+
!isArm64ECMangledFunctionName(u->getName()))
1365+
continue;
1366+
}
1367+
u->setWeakAlias(addUndefined(to));
1368+
}
1369+
}
1370+
}
1371+
13471372
// Parses /aligncomm option argument.
13481373
void SymbolTable::parseAligncomm(StringRef s) {
13491374
auto [name, align] = s.split(',');

lld/COFF/SymbolTable.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class SymbolTable {
6969
// symbols and warn about imported local symbols.
7070
void resolveRemainingUndefines();
7171

72+
// Try to resolve undefined symbols with alternate names.
73+
void resolveAlternateNames();
74+
7275
// Load lazy objects that are needed for MinGW automatic import and for
7376
// doing stdcall fixups.
7477
void loadMinGWSymbols();

lld/test/COFF/pdb-empty-sec.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// REQUIRES: x86
2+
3+
// RUN: llvm-mc -filetype=obj -triple=x86_64-windows %s -o %t.obj
4+
// RUN: lld-link -dll -noentry -debug %t.obj -out:%t.dll
5+
// RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s
6+
7+
// CHECK: Records
8+
// CHECK-NEXT: 0 | S_PUB32 [size = 20] `func`
9+
// CHECK-NEXT: flags = none, addr = 0001:0000
10+
// CHECK-NEXT: 20 | S_PUB32 [size = 20] `sym`
11+
// CHECK-NEXT: flags = none, addr = 0000:0000
12+
13+
.globl sym
14+
.data
15+
sym:
16+
.text
17+
.globl func
18+
func:
19+
ret

llvm/docs/CodingStandards.rst

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,20 +1594,25 @@ Restrict Visibility
15941594
^^^^^^^^^^^^^^^^^^^
15951595

15961596
Functions and variables should have the most restricted visibility possible.
1597+
15971598
For class members, that means using appropriate ``private``, ``protected``, or
1598-
``public`` keyword to restrict their access. For non-member functions, variables,
1599-
and classes, that means restricting visibility to a single ``.cpp`` file if it's
1600-
not referenced outside that file.
1599+
``public`` keyword to restrict their access.
1600+
1601+
For non-member functions, variables, and classes, that means restricting
1602+
visibility to a single ``.cpp`` file if it is not referenced outside that file.
16011603

16021604
Visibility of file-scope non-member variables and functions can be restricted to
16031605
the current translation unit by using either the ``static`` keyword or an anonymous
1604-
namespace. Anonymous namespaces are a great language feature that tells the C++
1606+
namespace.
1607+
1608+
Anonymous namespaces are a great language feature that tells the C++
16051609
compiler that the contents of the namespace are only visible within the current
16061610
translation unit, allowing more aggressive optimization and eliminating the
1607-
possibility of symbol name collisions. Anonymous namespaces are to C++ as
1608-
``static`` is to C functions and global variables. While ``static`` is available
1609-
in C++, anonymous namespaces are more general: they can make entire classes
1610-
private to a file.
1611+
possibility of symbol name collisions.
1612+
1613+
Anonymous namespaces are to C++ as ``static`` is to C functions and global
1614+
variables. While ``static`` is available in C++, anonymous namespaces are more
1615+
general: they can make entire classes private to a file.
16111616

16121617
The problem with anonymous namespaces is that they naturally want to encourage
16131618
indentation of their body, and they reduce locality of reference: if you see a
@@ -1653,10 +1658,17 @@ Avoid putting declarations other than classes into anonymous namespaces:
16531658

16541659
} // namespace
16551660

1656-
When you are looking at "``runHelper``" in the middle of a large C++ file,
1657-
you have no immediate way to tell if this function is local to the file. In
1658-
contrast, when the function is marked static, you don't need to cross-reference
1659-
faraway places in the file to tell that the function is local.
1661+
When you are looking at ``runHelper`` in the middle of a large C++ file,
1662+
you have no immediate way to tell if this function is local to the file.
1663+
1664+
In contrast, when the function is marked static, you don't need to cross-reference
1665+
faraway places in the file to tell that the function is local:
1666+
1667+
.. code-block:: c++
1668+
1669+
static void runHelper() {
1670+
...
1671+
}
16601672

16611673
Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements
16621674
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

llvm/test/Transforms/LoopIdiom/reuse-lcssa-phi-scev-expansion.ll

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,67 @@ loop.3:
9696
exit:
9797
ret void
9898
}
99+
100+
declare i1 @cond()
101+
102+
define ptr @test_lcssa_reuse_preserve_lcssa() {
103+
; CHECK-LABEL: define ptr @test_lcssa_reuse_preserve_lcssa() {
104+
; CHECK-NEXT: [[ENTRY:.*:]]
105+
; CHECK-NEXT: br label %[[LOOP_0_HEADER:.*]]
106+
; CHECK: [[LOOP_0_HEADER]]:
107+
; CHECK-NEXT: br label %[[LOOP_1:.*]]
108+
; CHECK: [[LOOP_1]]:
109+
; CHECK-NEXT: [[IV_1:%.*]] = phi ptr [ null, %[[LOOP_0_HEADER]] ], [ [[IV_1_NEXT:%.*]], %[[LOOP_1]] ]
110+
; CHECK-NEXT: [[IV_1_NEXT]] = getelementptr i8, ptr [[IV_1]], i64 1
111+
; CHECK-NEXT: [[EC_1:%.*]] = call i1 @cond()
112+
; CHECK-NEXT: br i1 [[EC_1]], label %[[THEN:.*]], label %[[LOOP_1]]
113+
; CHECK: [[THEN]]:
114+
; CHECK-NEXT: [[IV_1_LCSSA:%.*]] = phi ptr [ [[IV_1]], %[[LOOP_1]] ]
115+
; CHECK-NEXT: [[C_2:%.*]] = call i1 @cond()
116+
; CHECK-NEXT: br i1 [[C_2]], label %[[LOOP_2_PREHEADER:.*]], label %[[LOOP_0_LATCH:.*]]
117+
; CHECK: [[LOOP_2_PREHEADER]]:
118+
; CHECK-NEXT: [[IV_1_LCSSA_LCSSA:%.*]] = phi ptr [ [[IV_1_LCSSA]], %[[THEN]] ]
119+
; CHECK-NEXT: [[STRLEN:%.*]] = call i64 @strlen(ptr null)
120+
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr [[IV_1_LCSSA]], i64 1
121+
; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[TMP0]], i64 [[STRLEN]]
122+
; CHECK-NEXT: br label %[[LOOP_2:.*]]
123+
; CHECK: [[LOOP_2]]:
124+
; CHECK-NEXT: [[IV_2:%.*]] = phi ptr [ [[RES:%.*]], %[[LOOP_2]] ], [ [[IV_1_LCSSA_LCSSA]], %[[LOOP_2_PREHEADER]] ]
125+
; CHECK-NEXT: [[RES]] = getelementptr i8, ptr [[IV_2]], i64 1
126+
; CHECK-NEXT: [[L:%.*]] = load i8, ptr [[IV_1_LCSSA_LCSSA]], align 1
127+
; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i8 [[L]], 0
128+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[LOOP_2]]
129+
; CHECK: [[LOOP_0_LATCH]]:
130+
; CHECK-NEXT: br label %[[LOOP_0_HEADER]]
131+
; CHECK: [[EXIT]]:
132+
; CHECK-NEXT: ret ptr [[SCEVGEP]]
133+
;
134+
entry:
135+
br label %loop.0.header
136+
137+
loop.0.header:
138+
br label %loop.1
139+
140+
loop.1:
141+
%iv.1 = phi ptr [ null, %loop.0.header ], [ %iv.1.next, %loop.1 ]
142+
%iv.1.next = getelementptr i8, ptr %iv.1, i64 1
143+
%ec.1 = call i1 @cond()
144+
br i1 %ec.1, label %then, label %loop.1
145+
146+
then:
147+
%c.2 = call i1 @cond()
148+
br i1 %c.2, label %loop.2, label %loop.0.latch
149+
150+
loop.2:
151+
%iv.2 = phi ptr [ %res, %loop.2 ], [ %iv.1, %then ]
152+
%res = getelementptr i8, ptr %iv.2, i64 1
153+
%l = load i8, ptr %iv.1, align 1
154+
%ec.2 = icmp eq i8 %l, 0
155+
br i1 %ec.2, label %exit, label %loop.2
156+
157+
loop.0.latch:
158+
br label %loop.0.header
159+
160+
exit:
161+
ret ptr %res
162+
}

0 commit comments

Comments
 (0)