Skip to content

Commit 3599a52

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-narrow-interleave
2 parents ac323a7 + aadfa9f commit 3599a52

23 files changed

+1951
-1635
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
fetch-depth: 1
6666
- name: Get subprojects that have doc changes
6767
id: docs-changed-subprojects
68-
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
68+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
6969
with:
7070
files_yaml: |
7171
llvm:

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- name: Get changed files
3434
id: changed-files
35-
uses: tj-actions/changed-files@fea790cb660e33aef4bdf07304e28fedd77dfa13 # v39.2.4
35+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
3636
with:
3737
separator: ","
3838
skip_initial_fetch: true

lld/COFF/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ void ObjFile::handleComdatSelection(
705705
// seems better though.
706706
// (This behavior matches ModuleLinker::getComdatResult().)
707707
if (selection != leaderSelection) {
708-
Log(ctx) << "conflicting comdat type for " << leader << ": "
709-
<< (int)leaderSelection << " in " << leader->getFile() << " and "
710-
<< (int)selection << " in " << this;
708+
Log(ctx) << "conflicting comdat type for " << symtab.printSymbol(leader)
709+
<< ": " << (int)leaderSelection << " in " << leader->getFile()
710+
<< " and " << (int)selection << " in " << this;
711711
symtab.reportDuplicate(leader, this);
712712
return;
713713
}

lld/COFF/SymbolTable.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ struct UndefinedDiag {
214214
std::vector<File> files;
215215
};
216216

217-
static void reportUndefinedSymbol(COFFLinkerContext &ctx,
218-
const UndefinedDiag &undefDiag) {
217+
void SymbolTable::reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
219218
auto diag = errorOrWarn(ctx);
220-
diag << "undefined symbol: " << undefDiag.sym;
219+
diag << "undefined symbol: " << printSymbol(undefDiag.sym);
221220

222221
const size_t maxUndefReferences = 3;
223222
size_t numDisplayedRefs = 0, numRefs = 0;
@@ -363,12 +362,12 @@ void SymbolTable::reportProblemSymbols(
363362

364363
for (Symbol *b : ctx.config.gcroot) {
365364
if (undefs.count(b))
366-
errorOrWarn(ctx) << "<root>: undefined symbol: " << b;
365+
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
367366
if (localImports)
368367
if (Symbol *imp = localImports->lookup(b))
369-
Warn(ctx) << "<root>: locally defined symbol imported: " << imp
370-
<< " (defined in " << toString(imp->getFile())
371-
<< ") [LNK4217]";
368+
Warn(ctx) << "<root>: locally defined symbol imported: "
369+
<< printSymbol(imp) << " (defined in "
370+
<< toString(imp->getFile()) << ") [LNK4217]";
372371
}
373372

374373
std::vector<UndefinedDiag> undefDiags;
@@ -389,7 +388,8 @@ void SymbolTable::reportProblemSymbols(
389388
}
390389
if (localImports)
391390
if (Symbol *imp = localImports->lookup(sym))
392-
Warn(ctx) << file << ": locally defined symbol imported: " << imp
391+
Warn(ctx) << file
392+
<< ": locally defined symbol imported: " << printSymbol(imp)
393393
<< " (defined in " << imp->getFile() << ") [LNK4217]";
394394
}
395395
};
@@ -402,7 +402,7 @@ void SymbolTable::reportProblemSymbols(
402402
processFile(file, file->getSymbols());
403403

404404
for (const UndefinedDiag &undefDiag : undefDiags)
405-
reportUndefinedSymbol(ctx, undefDiag);
405+
reportUndefinedSymbol(undefDiag);
406406
}
407407

408408
void SymbolTable::reportUnresolvable() {
@@ -822,7 +822,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
822822
uint32_t newSectionOffset) {
823823
COFFSyncStream diag(ctx, ctx.config.forceMultiple ? DiagLevel::Warn
824824
: DiagLevel::Err);
825-
diag << "duplicate symbol: " << existing;
825+
diag << "duplicate symbol: " << printSymbol(existing);
826826

827827
DefinedRegular *d = dyn_cast<DefinedRegular>(existing);
828828
if (d && isa<ObjFile>(d->getFile())) {
@@ -1350,6 +1350,13 @@ Symbol *SymbolTable::addUndefined(StringRef name) {
13501350
return addUndefined(name, nullptr, false);
13511351
}
13521352

1353+
std::string SymbolTable::printSymbol(Symbol *sym) const {
1354+
std::string name = maybeDemangleSymbol(ctx, sym->getName());
1355+
if (ctx.hybridSymtab)
1356+
return name + (isEC() ? " (EC symbol)" : " (native symbol)");
1357+
return name;
1358+
}
1359+
13531360
void SymbolTable::compileBitcodeFiles() {
13541361
if (bitcodeFileInstances.empty())
13551362
return;

lld/COFF/SymbolTable.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct WrappedSymbol {
4141
Symbol *wrap;
4242
};
4343

44+
struct UndefinedDiag;
45+
4446
// SymbolTable is a bucket of all known symbols, including defined,
4547
// undefined, or lazy symbols (the last one is symbols in archive
4648
// files whose archive members are not yet loaded).
@@ -195,6 +197,8 @@ class SymbolTable {
195197
uint32_t loadConfigSize = 0;
196198
void initializeLoadConfig();
197199

200+
std::string printSymbol(Symbol *sym) const;
201+
198202
private:
199203
/// Given a name without "__imp_" prefix, returns a defined symbol
200204
/// with the "__imp_" prefix, if it exists.
@@ -216,6 +220,7 @@ class SymbolTable {
216220
reportProblemSymbols(const llvm::SmallPtrSetImpl<Symbol *> &undefs,
217221
const llvm::DenseMap<Symbol *, Symbol *> *localImports,
218222
bool needBitcodeFiles);
223+
void reportUndefinedSymbol(const UndefinedDiag &undefDiag);
219224
};
220225

221226
std::vector<std::string> getSymbolLocations(ObjFile *file, uint32_t symIndex);

lld/COFF/Symbols.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ coff::operator<<(const COFFSyncStream &s,
6060
return s;
6161
}
6262

63-
const COFFSyncStream &coff::operator<<(const COFFSyncStream &s, Symbol *sym) {
64-
return s << maybeDemangleSymbol(s.ctx, sym->getName());
65-
}
66-
6763
namespace coff {
6864

6965
void Symbol::computeName() {

lld/COFF/Symbols.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class SymbolTable;
3838

3939
const COFFSyncStream &operator<<(const COFFSyncStream &,
4040
const llvm::object::Archive::Symbol *);
41-
const COFFSyncStream &operator<<(const COFFSyncStream &, Symbol *);
4241

4342
// The base class for real symbol classes.
4443
class Symbol {

lld/COFF/Writer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,12 +1282,13 @@ void Writer::createImportTables() {
12821282
ctx.config.dllOrder[dll] = ctx.config.dllOrder.size();
12831283

12841284
if (file->impSym && !isa<DefinedImportData>(file->impSym))
1285-
Fatal(ctx) << file->impSym << " was replaced";
1285+
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
12861286
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
12871287
if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
12881288
if (!file->thunkSym)
12891289
Fatal(ctx) << "cannot delay-load " << toString(file)
1290-
<< " due to import of data: " << impSym;
1290+
<< " due to import of data: "
1291+
<< file->symtab.printSymbol(impSym);
12911292
delayIdata.add(impSym);
12921293
} else {
12931294
idata.add(impSym);
@@ -1306,15 +1307,17 @@ void Writer::appendImportThunks() {
13061307

13071308
if (file->thunkSym) {
13081309
if (!isa<DefinedImportThunk>(file->thunkSym))
1309-
Fatal(ctx) << file->thunkSym << " was replaced";
1310+
Fatal(ctx) << file->symtab.printSymbol(file->thunkSym)
1311+
<< " was replaced";
13101312
auto *chunk = cast<DefinedImportThunk>(file->thunkSym)->getChunk();
13111313
if (chunk->live)
13121314
textSec->addChunk(chunk);
13131315
}
13141316

13151317
if (file->auxThunkSym) {
13161318
if (!isa<DefinedImportThunk>(file->auxThunkSym))
1317-
Fatal(ctx) << file->auxThunkSym << " was replaced";
1319+
Fatal(ctx) << file->symtab.printSymbol(file->auxThunkSym)
1320+
<< " was replaced";
13181321
auto *chunk = cast<DefinedImportThunk>(file->auxThunkSym)->getChunk();
13191322
if (chunk->live)
13201323
textSec->addChunk(chunk);

lld/test/COFF/arm64x-altnames.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// RUN: 2>&1 | FileCheck --check-prefix=ERR-NATIVE %s
1313

1414
// ERR-NATIVE-NOT: test-arm64ec.obj
15-
// ERR-NATIVE: lld-link: error: undefined symbol: sym
15+
// ERR-NATIVE: lld-link: error: undefined symbol: sym (native symbol)
1616
// ERR-NATIVE-NEXT: >>> referenced by test-arm64.obj:(.test)
1717
// ERR-NATIVE-NOT: test-arm64ec.obj
1818

@@ -25,7 +25,7 @@
2525
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
2626

2727
// ERR-EC-NOT: test-arm64.obj
28-
// ERR-EC: lld-link: error: undefined symbol: sym
28+
// ERR-EC: lld-link: error: undefined symbol: sym (EC symbol)
2929
// ERR-EC-NEXT: >>> referenced by test-arm64ec.obj:(.test)
3030
// ERR-EC-NOT: test-arm64.obj
3131

lld/test/COFF/arm64x-incl.s

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
// Check that including a missing symbol results in an error.
4141

4242
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj -include:sym sym-aarch64.obj \
43-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
44-
// ERR: lld-link: error: <root>: undefined symbol: sym
43+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
44+
// ERR-EC: lld-link: error: <root>: undefined symbol: sym (EC symbol)
4545

4646
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj drectve-arm64ec.obj sym-aarch64.obj \
47-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
47+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-EC %s
4848

4949
// RUN: not lld-link -machine:arm64x -out:err.dll -dll -noentry loadconfig-arm64.obj loadconfig-arm64ec.obj drectve-aarch64.obj sym-arm64ec.obj \
50-
// RUN: 2>&1 | FileCheck --check-prefix=ERR %s
50+
// RUN: 2>&1 | FileCheck --check-prefix=ERR-NATIVE %s
51+
// ERR-NATIVE: lld-link: error: <root>: undefined symbol: sym (native symbol)
5152

5253
#--- sym-aarch64.s
5354
.section ".test","dr"

lld/test/COFF/arm64x-symtab.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
// RUN: not lld-link -machine:arm64x -dll -noentry -out:err1.dll symref-aarch64.obj sym-arm64ec.obj \
2020
// RUN: 2>&1 | FileCheck --check-prefix=UNDEF %s
21-
// UNDEF: lld-link: error: undefined symbol: sym
21+
// UNDEF: lld-link: error: undefined symbol: sym (native symbol)
2222
// UNDEF-NEXT: >>> referenced by symref-aarch64.obj:(.data)
2323

2424
// Check that EC object files can't reference native symbols.
2525

2626
// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-arm64ec.obj sym-aarch64.obj \
2727
// RUN: 2>&1 | FileCheck --check-prefix=UNDEFEC %s
28-
// UNDEFEC: lld-link: error: undefined symbol: sym
28+
// UNDEFEC: lld-link: error: undefined symbol: sym (EC symbol)
2929
// UNDEFEC-NEXT: >>> referenced by symref-arm64ec.obj:(.data)
3030

3131
// RUN: not lld-link -machine:arm64x -dll -noentry -out:out.dll symref-x86_64.obj sym-aarch64.obj \
3232
// RUN: 2>&1 | FileCheck --check-prefix=UNDEFX86 %s
33-
// UNDEFX86: lld-link: error: undefined symbol: sym
33+
// UNDEFX86: lld-link: error: undefined symbol: sym (EC symbol)
3434
// UNDEFX86-NEXT: >>> referenced by symref-x86_64.obj:(.data)
3535

3636
// RUN: not lld-link -machine:arm64x -dll -noentry -out:err2.dll symref-aarch64.obj sym-x86_64.obj \

lld/test/COFF/locally-imported-arm64x.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows %s -o %t.arm64ec.obj
55

66
// RUN: lld-link -machine:arm64x -dll -noentry %t.arm64.obj %t.arm64ec.obj -out:%t.dll 2>&1 | FileCheck --check-prefix=WARN %s
7-
// WARN: lld-link: warning: {{.*}}.arm64.obj: locally defined symbol imported: func
8-
// WARN-NEXT: lld-link: warning: {{.*}}.arm64ec.obj: locally defined symbol imported: func
7+
// WARN: lld-link: warning: {{.*}}.arm64.obj: locally defined symbol imported: func (native symbol)
8+
// WARN-NEXT: lld-link: warning: {{.*}}.arm64ec.obj: locally defined symbol imported: func (EC symbol)
99

1010
// RUN: llvm-readobj --hex-dump=.test %t.dll | FileCheck --check-prefix=TEST %s
1111
// TEST: 0x180005000 00300000 08300000

llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
5858
bool IsKasan, uint64_t *ShadowBase,
5959
int *MappingScale, bool *OrShadowOffset);
6060

61+
/// Remove memory attributes that are incompatible with the instrumentation
62+
/// added by AddressSanitizer and HWAddressSanitizer.
63+
/// \p ReadsArgMem - indicates whether function arguments may be read by
64+
/// instrumentation and require removing `writeonly` attributes.
65+
void removeASanIncompatibleFnAttributes(Function &F, bool ReadsArgMem);
66+
6167
} // namespace llvm
6268

6369
#endif

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,17 @@ std::optional<int64_t> PPCMCExpr::evaluateAsInt64(int64_t Value) const {
7373

7474
bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
7575
const MCFixup *Fixup) const {
76+
if (!Asm)
77+
return false;
7678
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
7779
return false;
7880

81+
// The signedness of the result is dependent on the instruction operand. E.g.
82+
// in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
83+
// parse time (!Asm), disable the folding.
7984
std::optional<int64_t> MaybeInt = evaluateAsInt64(Res.getConstant());
8085
if (Res.isAbsolute() && MaybeInt) {
81-
int64_t Result = *MaybeInt;
82-
bool IsHalf16 = Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16;
83-
bool IsHalf16DS =
84-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16ds;
85-
bool IsHalf16DQ =
86-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16dq;
87-
bool IsHalf = IsHalf16 || IsHalf16DS || IsHalf16DQ;
88-
89-
if (!IsHalf && Result >= 0x8000)
90-
return false;
91-
if ((IsHalf16DS && (Result & 0x3)) || (IsHalf16DQ && (Result & 0xf)))
92-
return false;
93-
94-
Res = MCValue::get(Result);
86+
Res = MCValue::get(*MaybeInt);
9587
} else {
9688
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
9789
getKind());

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,45 @@ void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
612612
*OrShadowOffset = Mapping.OrShadowOffset;
613613
}
614614

615+
void removeASanIncompatibleFnAttributes(Function &F, bool ReadsArgMem) {
616+
// Sanitizer checks read from shadow, which invalidates memory(argmem: *).
617+
//
618+
// This is not only true for sanitized functions, because AttrInfer can
619+
// infer those attributes on libc functions, which is not true if those
620+
// are instrumented (Android) or intercepted.
621+
//
622+
// We might want to model ASan shadow memory more opaquely to get rid of
623+
// this problem altogether, by hiding the shadow memory write in an
624+
// intrinsic, essentially like in the AArch64StackTagging pass. But that's
625+
// for another day.
626+
627+
// The API is weird. `onlyReadsMemory` actually means "does not write", and
628+
// `onlyWritesMemory` actually means "does not read". So we reconstruct
629+
// "accesses memory" && "does not read" <=> "writes".
630+
bool Changed = false;
631+
if (!F.doesNotAccessMemory()) {
632+
bool WritesMemory = !F.onlyReadsMemory();
633+
bool ReadsMemory = !F.onlyWritesMemory();
634+
if ((WritesMemory && !ReadsMemory) || F.onlyAccessesArgMemory()) {
635+
F.removeFnAttr(Attribute::Memory);
636+
Changed = true;
637+
}
638+
}
639+
if (ReadsArgMem) {
640+
for (Argument &A : F.args()) {
641+
if (A.hasAttribute(Attribute::WriteOnly)) {
642+
A.removeAttr(Attribute::WriteOnly);
643+
Changed = true;
644+
}
645+
}
646+
}
647+
if (Changed) {
648+
// nobuiltin makes sure later passes don't restore assumptions about
649+
// the function.
650+
F.addFnAttr(Attribute::NoBuiltin);
651+
}
652+
}
653+
615654
ASanAccessInfo::ASanAccessInfo(int32_t Packed)
616655
: Packed(Packed),
617656
AccessSizeIndex((Packed >> kAccessSizeIndexShift) & kAccessSizeIndexMask),
@@ -2733,6 +2772,9 @@ GlobalVariable *ModuleAddressSanitizer::getOrCreateModuleName() {
27332772
bool ModuleAddressSanitizer::instrumentModule() {
27342773
initializeCallbacks();
27352774

2775+
for (Function &F : M)
2776+
removeASanIncompatibleFnAttributes(F, /*ReadsArgMem=*/false);
2777+
27362778
// Create a module constructor. A destructor is created lazily because not all
27372779
// platforms, and not all modules need it.
27382780
if (ConstructorKind == AsanCtorKind::Global) {

0 commit comments

Comments
 (0)