Skip to content

Commit d53296a

Browse files
Merge branch 'amd-staging' into amd/dev/prbhanda_amdeng/SWDEV_503141
2 parents 4aa036c + 5ea58a4 commit d53296a

File tree

2,190 files changed

+87199
-40118
lines changed

Some content is hidden

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

2,190 files changed

+87199
-40118
lines changed

.github/new-prs-labeler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ clang:static analyzer:
499499
- clang/tools/scan-build/**
500500
- clang/utils/analyzer/**
501501
- clang/docs/analyzer/**
502+
- clang/test/Analysis/**
502503

503504
pgo:
504505
- llvm/lib/Transforms/Instrumentation/CGProfile.cpp

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
stage1:
3838
if: github.repository_owner == 'llvm'
3939
runs-on: libcxx-self-hosted-linux
40-
container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
40+
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
4141
continue-on-error: false
4242
strategy:
4343
fail-fast: false
@@ -48,8 +48,8 @@ jobs:
4848
'generic-cxx26',
4949
'generic-modules'
5050
]
51-
cc: [ 'clang-20' ]
52-
cxx: [ 'clang++-20' ]
51+
cc: [ 'clang-21' ]
52+
cxx: [ 'clang++-21' ]
5353
include:
5454
- config: 'generic-gcc'
5555
cc: 'gcc-14'
@@ -75,7 +75,7 @@ jobs:
7575
stage2:
7676
if: github.repository_owner == 'llvm'
7777
runs-on: libcxx-self-hosted-linux
78-
container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
78+
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
7979
needs: [ stage1 ]
8080
continue-on-error: false
8181
strategy:
@@ -88,18 +88,22 @@ jobs:
8888
'generic-cxx20',
8989
'generic-cxx23'
9090
]
91-
cc: [ 'clang-20' ]
92-
cxx: [ 'clang++-20' ]
91+
cc: [ 'clang-21' ]
92+
cxx: [ 'clang++-21' ]
9393
include:
9494
- config: 'generic-gcc-cxx11'
9595
cc: 'gcc-14'
9696
cxx: 'g++-14'
97-
- config: 'generic-cxx23'
98-
cc: 'clang-18'
99-
cxx: 'clang++-18'
97+
- config: 'generic-cxx26'
98+
cc: 'clang-20'
99+
cxx: 'clang++-20'
100100
- config: 'generic-cxx26'
101101
cc: 'clang-19'
102102
cxx: 'clang++-19'
103+
# Release transition
104+
- config: 'generic-cxx23'
105+
cc: 'clang-18'
106+
cxx: 'clang++-18'
103107
steps:
104108
- uses: actions/checkout@v4
105109
- name: ${{ matrix.config }}
@@ -120,7 +124,7 @@ jobs:
120124
**/crash_diagnostics/*
121125
stage3:
122126
if: github.repository_owner == 'llvm'
123-
needs: [ stage1, stage2 ]
127+
needs: [ stage2 ]
124128
continue-on-error: false
125129
strategy:
126130
fail-fast: false
@@ -163,14 +167,14 @@ jobs:
163167
- config: 'generic-msan'
164168
machine: libcxx-self-hosted-linux
165169
runs-on: ${{ matrix.machine }}
166-
container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
170+
container: ghcr.io/llvm/libcxx-linux-builder:b319dfef21f6c7b0bc6a356d6b9f41a3b3b98ae9
167171
steps:
168172
- uses: actions/checkout@v4
169173
- name: ${{ matrix.config }}
170174
run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
171175
env:
172-
CC: clang-20
173-
CXX: clang++-20
176+
CC: clang-21
177+
CXX: clang++-21
174178
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
175179
if: always()
176180
with:
@@ -184,7 +188,7 @@ jobs:
184188
**/crash_diagnostics/*
185189
186190
macos:
187-
needs: [ stage1 ]
191+
needs: [ stage3 ]
188192
strategy:
189193
fail-fast: false
190194
matrix:
@@ -228,7 +232,7 @@ jobs:
228232
229233
windows:
230234
runs-on: windows-2022
231-
needs: [ stage1 ]
235+
needs: [ stage2 ]
232236
strategy:
233237
fail-fast: false
234238
matrix:

.github/workflows/premerge.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ on:
1414
# do this is that it allows us to take advantage of concurrency groups
1515
# to cancel in progress CI jobs whenever the PR is closed.
1616
- closed
17-
paths:
18-
- .github/workflows/premerge.yaml
1917
push:
2018
branches:
2119
- 'main'
@@ -27,6 +25,7 @@ concurrency:
2725

2826
jobs:
2927
premerge-checks-linux:
28+
name: Linux Premerge Checks (Test Only - Please Ignore Results)
3029
if: >-
3130
github.repository_owner == 'llvm' &&
3231
(github.event_name != 'pull_request' || github.event.action != 'closed')
@@ -85,6 +84,7 @@ jobs:
8584
./.ci/monolithic-linux.sh "$(echo ${linux_projects} | tr ' ' ';')" "$(echo ${linux_check_targets})" "$(echo ${linux_runtimes} | tr ' ' ';')" "$(echo ${linux_runtime_check_targets})"
8685
8786
premerge-checks-windows:
87+
name: Windows Premerge Checks (Test Only - Please Ignore Results)
8888
if: >-
8989
github.repository_owner == 'llvm' &&
9090
(github.event_name != 'pull_request' || github.event.action != 'closed')
@@ -145,6 +145,7 @@ jobs:
145145
bash .ci/monolithic-windows.sh "${{ steps.vars.outputs.windows-projects }}" "${{ steps.vars.outputs.windows-check-targets }}"
146146
147147
premerge-check-macos:
148+
name: MacOS Premerge Checks
148149
runs-on: macos-14
149150
if: >-
150151
github.repository_owner == 'llvm' &&

.github/workflows/release-binaries.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ jobs:
138138
arches=arm64
139139
else
140140
arches=x86_64
141+
# Disable Flang builds on macOS x86_64. The FortranLower library takes
142+
# 2-3 hours to build on macOS, much slower than on Linux.
143+
# The long build time causes the release build to time out on x86_64,
144+
# so we need to disable flang there.
145+
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
141146
fi
142147
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
143148
fi

bolt/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,11 @@ endif()
202202

203203
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in
204204
${CMAKE_CURRENT_BINARY_DIR}/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc @ONLY)
205+
206+
set(BOLT_ENUM_TARGETS "")
207+
foreach(t ${BOLT_TARGETS_TO_BUILD})
208+
set(BOLT_ENUM_TARGETS "${BOLT_ENUM_TARGETS}BOLT_TARGET(${t})\n")
209+
endforeach(t)
210+
211+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/bolt/Core/TargetConfig.def.in
212+
${CMAKE_CURRENT_BINARY_DIR}/include/bolt/Core/TargetConfig.def @ONLY)

bolt/docs/BinaryAnalysis.md

Lines changed: 175 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,182 @@ analyses implemented in the BOLT libraries.
99

1010
## Which binary analyses are implemented?
1111

12-
At the moment, no binary analyses are implemented.
12+
* [Security scanners](#security-scanners)
13+
* [pac-ret analysis](#pac-ret-analysis)
1314

14-
The goal is to make it easy using a plug-in framework to add your own analyses.
15+
### Security scanners
16+
17+
For the past 25 years, a large numbers of exploits have been built and used in
18+
the wild to undermine computer security. The majority of these exploits abuse
19+
memory vulnerabilities in programs, see evidence from
20+
[Microsoft](https://youtu.be/PjbGojjnBZQ?si=oCHCa0SHgaSNr6Gr&t=836),
21+
[Chromium](https://www.chromium.org/Home/chromium-security/memory-safety/) and
22+
[Android](https://security.googleblog.com/2021/01/data-driven-security-hardening-in.html).
23+
24+
It is not surprising therefore, that a large number of mitigations have been
25+
added to instruction sets and toolchains to make it harder to build an exploit
26+
using a memory vulnerability. Examples are: stack canaries, stack clash,
27+
pac-ret, shadow stacks, arm64e, and many more.
28+
29+
These mitigations guarantee a so-called "security property" on the binaries they
30+
produce. For example, for stack canaries, the security property is roughly that
31+
a canary is located on the stack between the set of saved registers and the set
32+
of local variables. For pac-ret, it is roughly that either the return address is
33+
never stored/retrieved to/from memory; or, there are no writes to the register
34+
containing the return address between an instruction authenticating it and a
35+
return instruction using it.
36+
37+
From time to time, however, a bug gets found in the implementation of such
38+
mitigations in toolchains. Also, code that is written in assembler by hand
39+
requires the developer to ensure these security properties by hand.
40+
41+
In short, it is sometimes found that a few places in the binary code are not
42+
protected as well as expected given the requested mitigations. Attackers could
43+
make use of those places (sometimes called gadgets) to circumvent the protection
44+
that the mitigation should give.
45+
46+
One of the reasons that such gadgets, or holes in the mitigation implementation,
47+
exist is that typically the amount of testing and verification for these
48+
security properties is limited to checking results on specific examples.
49+
50+
In comparison, for testing functional correctness, or for testing performance,
51+
toolchain and software in general typically get tested with large test suites
52+
and benchmarks. In contrast, this typically does not get done for testing the
53+
security properties of binary code.
54+
55+
Unlike functional correctness where compilation errors result in test failures,
56+
and performance where speed and size differences are measurable, broken security
57+
properties cannot be easily observed using existing testing and benchmarking
58+
tools.
59+
60+
The security scanners implemented in `llvm-bolt-binary-analysis` aim to enable
61+
the testing of security hardening in arbitrary programs and not just specific
62+
examples.
63+
64+
65+
#### pac-ret analysis
66+
67+
`pac-ret` protection is a security hardening scheme implemented in compilers
68+
such as GCC and Clang, using the command line option
69+
`-mbranch-protection=pac-ret`. This option is enabled by default on most widely
70+
used Linux distributions.
71+
72+
The hardening scheme mitigates
73+
[Return-Oriented Programming (ROP)](https://llsoftsec.github.io/llsoftsecbook/#return-oriented-programming)
74+
attacks by making sure that return addresses are only ever stored to memory with
75+
a cryptographic hash, called a
76+
["Pointer Authentication Code" (PAC)](https://llsoftsec.github.io/llsoftsecbook/#pointer-authentication),
77+
in the upper bits of the pointer. This makes it substantially harder for
78+
attackers to divert control flow by overwriting a return address with a
79+
different value.
80+
81+
The hardening scheme relies on compilers producing appropriate code sequences when
82+
processing return addresses, especially when these are stored to and retrieved
83+
from memory.
84+
85+
The `pac-ret` binary analysis can be invoked using the command line option
86+
`--scanners=pac-ret`. It makes `llvm-bolt-binary-analysis` scan through the
87+
provided binary, checking each function for the following security property:
88+
89+
> For each procedure and exception return instruction, the destination register
90+
> must have one of the following properties:
91+
>
92+
> 1. be immutable within the function, or
93+
> 2. the last write to the register must be by an authenticating instruction. This
94+
> includes combined authentication and return instructions such as `RETAA`.
95+
96+
##### Example 1
97+
98+
For example, a typical non-pac-ret-protected function looks as follows:
99+
100+
```
101+
stp x29, x30, [sp, #-0x10]!
102+
mov x29, sp
103+
bl g@PLT
104+
add x0, x0, #0x3
105+
ldp x29, x30, [sp], #0x10
106+
ret
107+
```
108+
109+
The return instruction `ret` implicitly uses register `x30` as the address to
110+
return to. Register `x30` was last written by instruction `ldp`, which is not an
111+
authenticating instruction. `llvm-bolt-binary-analysis --scanners=pac-ret` will
112+
report this as follows:
113+
114+
```
115+
GS-PACRET: non-protected ret found in function f1, basic block .LBB00, at address 10310
116+
The return instruction is 00010310: ret # pacret-gadget: pac-ret-gadget<Ret:MCInstBBRef<BB:.LBB00:6>, Overwriting:[MCInstBBRef<BB:.LBB00:5> ]>
117+
The 1 instructions that write to the return register after any authentication are:
118+
1. 0001030c: ldp x29, x30, [sp], #0x10
119+
This happens in the following basic block:
120+
000102fc: stp x29, x30, [sp, #-0x10]!
121+
00010300: mov x29, sp
122+
00010304: bl g@PLT
123+
00010308: add x0, x0, #0x3
124+
0001030c: ldp x29, x30, [sp], #0x10
125+
00010310: ret # pacret-gadget: pac-ret-gadget<Ret:MCInstBBRef<BB:.LBB00:6>, Overwriting:[MCInstBBRef<BB:.LBB00:5> ]>
126+
```
127+
128+
The exact format of how `llvm-bolt-binary-analysis` reports this is expected to
129+
evolve over time.
130+
131+
##### Example 2: multiple "last-overwriting" instructions
132+
133+
A simple example that shows how there can be a set of "last overwriting"
134+
instructions of a register follows:
135+
136+
```
137+
paciasp
138+
stp x29, x30, [sp, #-0x10]!
139+
ldp x29, x30, [sp], #0x10
140+
cbnz x0, 1f
141+
autiasp
142+
1:
143+
ret
144+
```
145+
146+
This will produce the following diagnostic:
147+
148+
```
149+
GS-PACRET: non-protected ret found in function f_crossbb1, basic block .Ltmp0, at address 102dc
150+
The return instruction is 000102dc: ret # pacret-gadget: pac-ret-gadget<Ret:MCInstBBRef<BB:.Ltmp0:0>, Overwriting:[MCInstBBRef<BB:.LFT0:0> MCInstBBRef<BB:.LBB00:2> ]>
151+
The 2 instructions that write to the return register after any authentication are:
152+
1. 000102d0: ldp x29, x30, [sp], #0x10
153+
2. 000102d8: autiasp
154+
```
155+
156+
(Yes, this diagnostic could be improved because the second "overwriting"
157+
instruction, `autiasp`, is an authenticating instruction...)
158+
159+
##### Known false positives or negatives
160+
161+
The following are current known cases of false positives:
162+
163+
1. Not handling "no-return" functions. See issue
164+
[#115154](https://github.com/llvm/llvm-project/issues/115154) for details and
165+
pointers to open PRs to fix this.
166+
2. Not recognizing that a move of a properly authenticated value between registers,
167+
results in the destination register having a properly authenticated value.
168+
For example, the scanner currently produces a false negative for the following
169+
code sequence:
170+
```
171+
autiasp
172+
mov x16, x30
173+
ret x16
174+
```
175+
176+
The following are current known cases of false negatives:
177+
178+
1. Not handling functions for which the CFG cannot be reconstructed by BOLT. The
179+
plan is to implement support for this, picking up the implementation from the
180+
[prototype branch](
181+
https://github.com/llvm/llvm-project/compare/main...kbeyls:llvm-project:bolt-gadget-scanner-prototype).
182+
183+
BOLT cannot currently handle functions with `cfi_negate_ra_state` correctly,
184+
i.e. any binaries built with `-mbranch-protection=pac-ret`. The scanner is meant
185+
to be used on specifically such binaries, so this is a major limitation! Work is
186+
going on in PR [#120064](https://github.com/llvm/llvm-project/pull/120064) to
187+
fix this.
15188

16189
## How to add your own binary analysis
17190

bolt/include/bolt/Core/Linker.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ class BOLTLinker {
4646
/// Return the address and size of a symbol or std::nullopt if it cannot be
4747
/// found.
4848
virtual std::optional<SymbolInfo> lookupSymbolInfo(StringRef Name) const = 0;
49-
50-
/// Return the address of a symbol or std::nullopt if it cannot be found.
51-
std::optional<uint64_t> lookupSymbol(StringRef Name) const {
52-
if (const auto Info = lookupSymbolInfo(Name))
53-
return Info->Address;
54-
return std::nullopt;
55-
}
5649
};
5750

5851
} // namespace bolt

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/MC/MCInstrAnalysis.h"
2828
#include "llvm/MC/MCInstrDesc.h"
2929
#include "llvm/MC/MCInstrInfo.h"
30+
#include "llvm/MC/MCRegister.h"
3031
#include "llvm/Support/Allocator.h"
3132
#include "llvm/Support/Casting.h"
3233
#include "llvm/Support/ErrorHandling.h"
@@ -550,6 +551,22 @@ class MCPlusBuilder {
550551
return Analysis->isReturn(Inst);
551552
}
552553

554+
virtual ErrorOr<MCPhysReg> getAuthenticatedReg(const MCInst &Inst) const {
555+
llvm_unreachable("not implemented");
556+
return getNoRegister();
557+
}
558+
559+
virtual bool isAuthenticationOfReg(const MCInst &Inst,
560+
MCPhysReg AuthenticatedReg) const {
561+
llvm_unreachable("not implemented");
562+
return false;
563+
}
564+
565+
virtual ErrorOr<MCPhysReg> getRegUsedAsRetDest(const MCInst &Inst) const {
566+
llvm_unreachable("not implemented");
567+
return getNoRegister();
568+
}
569+
553570
virtual bool isTerminator(const MCInst &Inst) const;
554571

555572
virtual bool isNoop(const MCInst &Inst) const {

0 commit comments

Comments
 (0)