Skip to content

Commit fc10370

Browse files
committed
Merge remote-tracking branch 'upstream/release/14.x' into rustc/14.0-2022-03-22
2 parents 326efc9 + 0e27d08 commit fc10370

File tree

60 files changed

+1027
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1027
-228
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3293,7 +3293,7 @@ Work around VLLDM erratum CVE-2021-35465 (ARM only)
32933293

32943294
.. option:: -mno-bti-at-return-twice
32953295

3296-
Do not add a BTI instruction after a setjmp or other return-twice construct (Arm only)
3296+
Do not add a BTI instruction after a setjmp or other return-twice construct (AArch32/AArch64 only)
32973297

32983298
.. option:: -mno-movt
32993299

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ Arm and AArch64 Support in Clang
381381
- The ``attribute((target("branch-protection=...)))`` attributes will now also
382382
work for the ARM backend.
383383

384+
- When using ``-mbranch-protection=bti`` with AArch64, calls to setjmp will
385+
now be followed by a BTI instruction. This is done to be compatible with
386+
setjmp implementations that return with a br instead of a ret. You can
387+
disable this behaviour using the ``-mno-bti-at-return-twice`` option.
388+
384389
SPIR-V Support in Clang
385390
-----------------------
386391

@@ -391,7 +396,6 @@ SPIR-V Support in Clang
391396
- Added linking of separate object files in SPIR-V format using external
392397
``spirv-link`` tool.
393398

394-
395399
Floating Point Support in Clang
396400
-------------------------------
397401
- The default setting of FP contraction (FMA) is now -ffp-contract=on (for

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3372,7 +3372,7 @@ def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
33723372
def mno_bti_at_return_twice : Flag<["-"], "mno-bti-at-return-twice">,
33733373
Group<m_arm_Features_Group>,
33743374
HelpText<"Do not add a BTI instruction after a setjmp or other"
3375-
" return-twice construct (Arm only)">;
3375+
" return-twice construct (Arm/AArch64 only)">;
33763376

33773377
foreach i = {1-31} in
33783378
def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group<m_Group>,

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,15 +4895,25 @@ RValue CodeGenFunction::EmitSimpleCallExpr(const CallExpr *E,
48954895
return EmitCall(E->getCallee()->getType(), Callee, E, ReturnValue);
48964896
}
48974897

4898+
// Detect the unusual situation where an inline version is shadowed by a
4899+
// non-inline version. In that case we should pick the external one
4900+
// everywhere. That's GCC behavior too.
4901+
static bool OnlyHasInlineBuiltinDeclaration(const FunctionDecl *FD) {
4902+
for (const FunctionDecl *PD = FD; PD; PD = PD->getPreviousDecl())
4903+
if (!PD->isInlineBuiltinDeclaration())
4904+
return false;
4905+
return true;
4906+
}
4907+
48984908
static CGCallee EmitDirectCallee(CodeGenFunction &CGF, GlobalDecl GD) {
48994909
const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
49004910

49014911
if (auto builtinID = FD->getBuiltinID()) {
49024912
std::string FDInlineName = (FD->getName() + ".inline").str();
49034913
// When directing calling an inline builtin, call it through it's mangled
49044914
// name to make it clear it's not the actual builtin.
4905-
if (FD->isInlineBuiltinDeclaration() &&
4906-
CGF.CurFn->getName() != FDInlineName) {
4915+
if (CGF.CurFn->getName() != FDInlineName &&
4916+
OnlyHasInlineBuiltinDeclaration(FD)) {
49074917
llvm::Constant *CalleePtr = EmitFunctionDeclPointer(CGF.CGM, GD);
49084918
llvm::Function *Fn = llvm::cast<llvm::Function>(CalleePtr);
49094919
llvm::Module *M = Fn->getParent();

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,4 +592,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
592592
// Enabled A53 errata (835769) workaround by default on android
593593
Features.push_back("+fix-cortex-a53-835769");
594594
}
595+
596+
if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
597+
Features.push_back("+no-bti-at-return-twice");
595598
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
2+
//
3+
// Verifies that clang-generated *.inline are removed when shadowed by an
4+
// external definition, even when that definition appears at the end of the
5+
// file.
6+
7+
// CHECK-NOT: strlen.inline
8+
9+
extern unsigned long strlen(char const *s);
10+
11+
extern __inline __attribute__((__always_inline__)) __attribute__((__gnu_inline__)) unsigned long strlen(char const *s) {
12+
return 1;
13+
}
14+
15+
static unsigned long chesterfield(char const *s) {
16+
return strlen(s);
17+
}
18+
static unsigned long (*_strlen)(char const *ptr);
19+
20+
unsigned long blutch(char const *s) {
21+
return chesterfield(s);
22+
}
23+
24+
unsigned long strlen(char const *s) {
25+
return _strlen(s);
26+
}

compiler-rt/lib/asan/asan_linux.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,24 @@ static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
131131
VReport(2, "info->dlpi_name = %s\tinfo->dlpi_addr = %p\n", info->dlpi_name,
132132
(void *)info->dlpi_addr);
133133

134-
// Continue until the first dynamic library is found
135-
if (!info->dlpi_name || info->dlpi_name[0] == 0)
136-
return 0;
137-
138-
// Ignore vDSO
139-
if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
140-
return 0;
134+
const char **name = (const char **)data;
141135

142-
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
143136
// Ignore first entry (the main program)
144-
char **p = (char **)data;
145-
if (!(*p)) {
146-
*p = (char *)-1;
137+
if (!*name) {
138+
*name = "";
147139
return 0;
148140
}
149-
#endif
150141

151-
#if SANITIZER_SOLARIS
152-
// Ignore executable on Solaris
153-
if (info->dlpi_addr == 0)
142+
# if SANITIZER_LINUX
143+
// Ignore vDSO. glibc versions earlier than 2.15 (and some patched
144+
// by distributors) return an empty name for the vDSO entry, so
145+
// detect this as well.
146+
if (!info->dlpi_name[0] ||
147+
internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
154148
return 0;
155-
#endif
149+
# endif
156150

157-
*(const char **)data = info->dlpi_name;
151+
*name = info->dlpi_name;
158152
return 1;
159153
}
160154

@@ -175,7 +169,7 @@ void AsanCheckDynamicRTPrereqs() {
175169
// Ensure that dynamic RT is the first DSO in the list
176170
const char *first_dso_name = nullptr;
177171
dl_iterate_phdr(FindFirstDSOCallback, &first_dso_name);
178-
if (first_dso_name && !IsDynamicRTName(first_dso_name)) {
172+
if (first_dso_name && first_dso_name[0] && !IsDynamicRTName(first_dso_name)) {
179173
Report("ASan runtime does not come first in initial library list; "
180174
"you should either link runtime to your application or "
181175
"manually preload it with LD_PRELOAD.\n");

compiler-rt/lib/builtins/clear_cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ void __clear_cache(void *start, void *end) {
130130
__asm __volatile("dsb ish");
131131
}
132132
__asm __volatile("isb sy");
133-
#elif defined(__powerpc64__)
133+
#elif defined(__powerpc__)
134+
// Newer CPUs have a bigger line size made of multiple blocks, so the
135+
// following value is a minimal common denominator for what used to be
136+
// a single block cache line and is therefore inneficient.
134137
const size_t line_size = 32;
135138
const size_t len = (uintptr_t)end - (uintptr_t)start;
136139

libcxx/include/__support/openbsd/xlocale.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,24 @@
1616
#include <ctype.h>
1717
#include <cwctype>
1818

19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
24+
inline _LIBCPP_HIDE_FROM_ABI long
25+
strtol_l(const char *nptr, char **endptr, int base, locale_t) {
26+
return ::strtol(nptr, endptr, base);
27+
}
28+
29+
inline _LIBCPP_HIDE_FROM_ABI unsigned long
30+
strtoul_l(const char *nptr, char **endptr, int base, locale_t) {
31+
return ::strtoul(nptr, endptr, base);
32+
}
33+
34+
35+
#ifdef __cplusplus
36+
}
37+
#endif
38+
1939
#endif

lld/COFF/DebugTypes.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,11 @@ struct GHashTable {
902902

903903
/// A ghash table cell for deduplicating types from TpiSources.
904904
class GHashCell {
905-
uint64_t data = 0;
905+
// Force "data" to be 64-bit aligned; otherwise, some versions of clang
906+
// will generate calls to libatomic when using some versions of libstdc++
907+
// on 32-bit targets. (Also, in theory, there could be a target where
908+
// new[] doesn't always return an 8-byte-aligned allocation.)
909+
alignas(sizeof(uint64_t)) uint64_t data = 0;
906910

907911
public:
908912
GHashCell() = default;

lld/ELF/Writer.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -722,23 +722,30 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
722722
auto *sec = dyn_cast<OutputSection>(cmd);
723723
if (!sec)
724724
continue;
725-
auto i = llvm::find_if(sec->commands, [](SectionCommand *cmd) {
726-
if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
727-
return !isd->sections.empty();
728-
return false;
729-
});
730-
if (i == sec->commands.end())
731-
continue;
732-
InputSectionBase *isec = cast<InputSectionDescription>(*i)->sections[0];
733-
734-
// Relocations are not using REL[A] section symbols.
735-
if (isec->type == SHT_REL || isec->type == SHT_RELA)
736-
continue;
737-
738-
// Unlike other synthetic sections, mergeable output sections contain data
739-
// copied from input sections, and there may be a relocation pointing to its
740-
// contents if -r or --emit-reloc is given.
741-
if (isa<SyntheticSection>(isec) && !(isec->flags & SHF_MERGE))
725+
OutputSection &osec = *sec;
726+
InputSectionBase *isec = nullptr;
727+
// Iterate over all input sections and add a STT_SECTION symbol if any input
728+
// section may be a relocation target.
729+
for (SectionCommand *cmd : osec.commands) {
730+
auto *isd = dyn_cast<InputSectionDescription>(cmd);
731+
if (!isd)
732+
continue;
733+
for (InputSectionBase *s : isd->sections) {
734+
// Relocations are not using REL[A] section symbols.
735+
if (s->type == SHT_REL || s->type == SHT_RELA)
736+
continue;
737+
738+
// Unlike other synthetic sections, mergeable output sections contain
739+
// data copied from input sections, and there may be a relocation
740+
// pointing to its contents if -r or --emit-reloc is given.
741+
if (isa<SyntheticSection>(s) && !(s->flags & SHF_MERGE))
742+
continue;
743+
744+
isec = s;
745+
break;
746+
}
747+
}
748+
if (!isec)
742749
continue;
743750

744751
// Set the symbol to be relative to the output section so that its st_value

lld/test/ELF/emit-relocs-synthetic.s

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# REQUIRES: x86
2+
## Regression test: add STT_SECTION even if synthetic sections are interleaved
3+
## with regular input sections.
4+
5+
# RUN: rm -rf %t && split-file %s %t
6+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
7+
# RUN: ld.lld --emit-relocs --no-relax -T %t/1.t %t/a.o -o %t/a1
8+
# RUN: llvm-objdump -dr %t/a1 | FileCheck %s --check-prefixes=CHECK,CHECK1
9+
# RUN: ld.lld --emit-relocs --no-relax -T %t/2.t %t/a.o -o %t/a2
10+
# RUN: llvm-objdump -dr %t/a2 | FileCheck %s --check-prefixes=CHECK,CHECK2
11+
12+
# CHECK: <_start>:
13+
## %t/a1: bss is at offset 17. bss-4 = .bss + 0xd
14+
## %t/a2: bss is at offset 16. bss-4 = .bss + 0xc
15+
# CHECK-NEXT: movl [[#]](%rip), %eax
16+
# CHECK1-NEXT: R_X86_64_PC32 .bss+0xd
17+
# CHECK2-NEXT: R_X86_64_PC32 .bss+0xc
18+
# CHECK-NEXT: movl [[#]](%rip), %eax
19+
# CHECK-NEXT: R_X86_64_PC32 common-0x4
20+
# CHECK-NEXT: movl [[#]](%rip), %eax
21+
## %t/a1: input .data is at offset 8. 8-4 = 0x4
22+
## %t/a2: input .data is at offset 0. 0-4 = -0x4
23+
# CHECK1-NEXT: R_X86_64_GOTPCRELX .data+0x4
24+
# CHECK2-NEXT: R_X86_64_GOTPCRELX .data-0x4
25+
26+
#--- a.s
27+
.globl _start
28+
_start:
29+
movl bss(%rip), %eax
30+
movl common(%rip), %eax
31+
## Compilers don't produce this. We just check the behavior.
32+
movl .data@gotpcrel(%rip), %eax
33+
34+
.section .data,"aw",@progbits
35+
.quad 0
36+
37+
.section .bss,"aw",@nobits
38+
.space 16
39+
bss:
40+
.byte 0
41+
42+
.comm common,1,1
43+
44+
#--- 1.t
45+
SECTIONS {
46+
.data : { *(.got) *(.data) }
47+
.bss : { *(COMMON) *(.bss) }
48+
}
49+
50+
#--- 2.t
51+
SECTIONS {
52+
.data : { *(.data) *(.got) }
53+
.bss : { *(.bss) *(COMMON) }
54+
}

llvm/include/llvm/CodeGen/FastISel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class FastISel {
212212
const TargetRegisterInfo &TRI;
213213
const TargetLibraryInfo *LibInfo;
214214
bool SkipTargetIndependentISel;
215+
bool UseInstrRefDebugInfo = false;
215216

216217
/// The position of the last instruction for materializing constants
217218
/// for use in the current block. It resets to EmitStartPt when it makes sense
@@ -318,6 +319,12 @@ class FastISel {
318319
/// Reset InsertPt to the given old insert position.
319320
void leaveLocalValueArea(SavePoint Old);
320321

322+
/// Signal whether instruction referencing variable locations are desired for
323+
/// this function's debug-info.
324+
void useInstrRefDebugInfo(bool Flag) {
325+
UseInstrRefDebugInfo = Flag;
326+
}
327+
321328
protected:
322329
explicit FastISel(FunctionLoweringInfo &FuncInfo,
323330
const TargetLibraryInfo *LibInfo,

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ class SelectionDAG {
278278

279279
uint16_t NextPersistentId = 0;
280280

281+
/// Are instruction referencing variable locations desired for this function?
282+
bool UseInstrRefDebugInfo = false;
283+
281284
public:
282285
/// Clients of various APIs that cause global effects on
283286
/// the DAG can optionally implement this interface. This allows the clients
@@ -1702,6 +1705,16 @@ class SelectionDAG {
17021705
/// function mirrors \c llvm::salvageDebugInfo.
17031706
void salvageDebugInfo(SDNode &N);
17041707

1708+
/// Signal whether instruction referencing variable locations are desired for
1709+
/// this function's debug-info.
1710+
void useInstrRefDebugInfo(bool Flag) {
1711+
UseInstrRefDebugInfo = Flag;
1712+
}
1713+
1714+
bool getUseInstrRefDebugInfo() const {
1715+
return UseInstrRefDebugInfo;
1716+
}
1717+
17051718
void dump() const;
17061719

17071720
/// In most cases this function returns the ABI alignment for a given type,

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SelectionDAGISel : public MachineFunctionPass {
5353
const TargetLowering *TLI;
5454
bool FastISelFailed;
5555
SmallPtrSet<const Instruction *, 4> ElidedArgCopyInstrs;
56+
bool UseInstrRefDebugInfo = false;
5657

5758
/// Current optimization remark emitter.
5859
/// Used to report things like combines and FastISel failures.

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,6 @@ void MachineFunction::finalizeDebugInstrRefs() {
11811181
MI.getOperand(1).ChangeToRegister(0, false);
11821182
};
11831183

1184-
if (!useDebugInstrRef())
1185-
return;
1186-
11871184
for (auto &MBB : *this) {
11881185
for (auto &MI : MBB) {
11891186
if (!MI.isDebugRef() || !MI.getOperand(0).isReg())

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
12651265
// If using instruction referencing, mutate this into a DBG_INSTR_REF,
12661266
// to be later patched up by finalizeDebugInstrRefs. Tack a deref onto
12671267
// the expression, we don't have an "indirect" flag in DBG_INSTR_REF.
1268-
if (FuncInfo.MF->useDebugInstrRef() && Op->isReg()) {
1268+
if (UseInstrRefDebugInfo && Op->isReg()) {
12691269
Builder->setDesc(TII.get(TargetOpcode::DBG_INSTR_REF));
12701270
Builder->getOperand(1).ChangeToImmediate(0);
12711271
auto *NewExpr =
@@ -1324,7 +1324,7 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
13241324

13251325
// If using instruction referencing, mutate this into a DBG_INSTR_REF,
13261326
// to be later patched up by finalizeDebugInstrRefs.
1327-
if (FuncInfo.MF->useDebugInstrRef()) {
1327+
if (UseInstrRefDebugInfo) {
13281328
Builder->setDesc(TII.get(TargetOpcode::DBG_INSTR_REF));
13291329
Builder->getOperand(1).ChangeToImmediate(0);
13301330
}

0 commit comments

Comments
 (0)