Skip to content

Commit 769ee86

Browse files
authored
merge main into amd-staging
2 parents 1581072 + eb6e50f commit 769ee86

38 files changed

+2781
-2256
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
872872
const llvm::Triple &Triple = ToolChain.getTriple();
873873
const bool IsOSAIX = Triple.isOSAIX();
874874
const bool IsAMDGCN = Triple.isAMDGCN();
875-
const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
875+
StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ);
876+
const char *LinkerPath = Args.MakeArgString(ToolChain.GetLinkerPath());
876877
const Driver &D = ToolChain.getDriver();
877878
bool ClosedNeeded =
878879
checkForAMDProprietaryOptOptions(ToolChain, D, Args, CmdArgs,
@@ -881,9 +882,9 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
881882
const bool IsFatLTO = Args.hasFlag(options::OPT_ffat_lto_objects,
882883
options::OPT_fno_fat_lto_objects, false);
883884
const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
884-
if (llvm::sys::path::filename(Linker) != "ld.lld" &&
885-
llvm::sys::path::stem(Linker) != "ld.lld" && !ClosedNeeded &&
886-
!Triple.isOSOpenBSD()) {
885+
if (Linker != "lld" && Linker != "lld-link" &&
886+
llvm::sys::path::filename(LinkerPath) != "ld.lld" &&
887+
llvm::sys::path::stem(LinkerPath) != "ld.lld" && !Triple.isOSOpenBSD()) {
887888
// Tell the linker to load the plugin. This has to come before
888889
// AddLinkerInputs as gold requires -plugin and AIX ld requires -bplugin to
889890
// come before any -plugin-opt/-bplugin_opt that -Wl might forward.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ld.lld

clang/test/Driver/fat-lto-objects.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@
4949
// RUN: -fuse-ld=lld -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s
5050
// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \
5151
// RUN: -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=NOLTO %s
52+
// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \
53+
// RUN: -fuse-ld=lld --ld-path=%S/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper \
54+
// RUN: -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s
5255
// LTO: "--fat-lto-objects"
5356
// NOLTO-NOT: "--fat-lto-objects"

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,45 @@ INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
285285
return REAL(unlinkat)(fd, pathname, flag);
286286
}
287287

288+
INTERCEPTOR(int, stat, const char *pathname, struct stat *s) {
289+
__rtsan_notify_intercepted_call("stat");
290+
return REAL(stat)(pathname, s);
291+
}
292+
293+
INTERCEPTOR(int, lstat, const char *pathname, struct stat *s) {
294+
__rtsan_notify_intercepted_call("lstat");
295+
return REAL(lstat)(pathname, s);
296+
}
297+
298+
INTERCEPTOR(int, fstat, int fd, struct stat *s) {
299+
__rtsan_notify_intercepted_call("fstat");
300+
return REAL(fstat)(fd, s);
301+
}
302+
303+
#if !SANITIZER_APPLE // deprecated for darwin
304+
INTERCEPTOR(int, stat64, const char *pathname, struct stat64 *s) {
305+
__rtsan_notify_intercepted_call("stat64");
306+
return REAL(stat64)(pathname, s);
307+
}
308+
309+
INTERCEPTOR(int, lstat64, const char *pathname, struct stat64 *s) {
310+
__rtsan_notify_intercepted_call("lstat64");
311+
return REAL(lstat64)(pathname, s);
312+
}
313+
314+
INTERCEPTOR(int, fstat64, int fd, struct stat64 *s) {
315+
__rtsan_notify_intercepted_call("fstat64");
316+
return REAL(fstat64)(fd, s);
317+
}
318+
#define RTSAN_MAYBE_INTERCEPT_STAT64 INTERCEPT_FUNCTION(stat64)
319+
#define RTSAN_MAYBE_INTERCEPT_LSTAT64 INTERCEPT_FUNCTION(lstat64)
320+
#define RTSAN_MAYBE_INTERCEPT_FSTAT64 INTERCEPT_FUNCTION(fstat64)
321+
#else
322+
#define RTSAN_MAYBE_INTERCEPT_STAT64
323+
#define RTSAN_MAYBE_INTERCEPT_LSTAT64
324+
#define RTSAN_MAYBE_INTERCEPT_FSTAT64
325+
#endif
326+
288327
// Streams
289328

290329
INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
@@ -1437,6 +1476,12 @@ void __rtsan::InitializeInterceptors() {
14371476
RTSAN_MAYBE_INTERCEPT_READLINKAT;
14381477
INTERCEPT_FUNCTION(unlink);
14391478
INTERCEPT_FUNCTION(unlinkat);
1479+
INTERCEPT_FUNCTION(stat);
1480+
INTERCEPT_FUNCTION(lstat);
1481+
INTERCEPT_FUNCTION(fstat);
1482+
RTSAN_MAYBE_INTERCEPT_STAT64;
1483+
RTSAN_MAYBE_INTERCEPT_LSTAT64;
1484+
RTSAN_MAYBE_INTERCEPT_FSTAT64;
14401485
INTERCEPT_FUNCTION(fopen);
14411486
RTSAN_MAYBE_INTERCEPT_FOPEN64;
14421487
RTSAN_MAYBE_INTERCEPT_FREOPEN64;

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ TEST_F(RtsanFileTest, FcntlFlockDiesWhenRealtime) {
401401
ASSERT_THAT(fd, Ne(-1));
402402

403403
auto Func = [fd]() {
404-
struct flock lock {};
404+
struct flock lock{};
405405
lock.l_type = F_RDLCK;
406406
lock.l_whence = SEEK_SET;
407407
lock.l_start = 0;
@@ -735,7 +735,7 @@ TEST(TestRtsanInterceptors, IoctlBehavesWithOutputPointer) {
735735
GTEST_SKIP();
736736
}
737737

738-
struct ifreq ifr {};
738+
struct ifreq ifr{};
739739
strncpy(ifr.ifr_name, ifaddr->ifa_name, IFNAMSIZ - 1);
740740

741741
int retval = ioctl(sock, SIOCGIFADDR, &ifr);
@@ -875,6 +875,33 @@ TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
875875
ExpectNonRealtimeSurvival(Func);
876876
}
877877

878+
TEST_F(RtsanOpenedFileTest, StatDiesWhenRealtime) {
879+
auto Func = [&]() {
880+
struct stat s{};
881+
stat(GetTemporaryFilePath(), &s);
882+
};
883+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("stat"));
884+
ExpectNonRealtimeSurvival(Func);
885+
}
886+
887+
TEST_F(RtsanOpenedFileTest, LstatDiesWhenRealtime) {
888+
auto Func = [&]() {
889+
struct stat s{};
890+
lstat(GetTemporaryFilePath(), &s);
891+
};
892+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("lstat"));
893+
ExpectNonRealtimeSurvival(Func);
894+
}
895+
896+
TEST_F(RtsanOpenedFileTest, FstatDiesWhenRealtime) {
897+
auto Func = [&]() {
898+
struct stat s{};
899+
fstat(GetOpenFd(), &s);
900+
};
901+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fstat"));
902+
ExpectNonRealtimeSurvival(Func);
903+
}
904+
878905
TEST_F(RtsanFileTest, FcloseDiesWhenRealtime) {
879906
FILE *f = fopen(GetTemporaryFilePath(), "w");
880907
EXPECT_THAT(f, Ne(nullptr));

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_format.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ static const char *maybe_parse_length_modifier(const char *p, char ll[2]) {
6767

6868
// Returns true if the character is an integer conversion specifier.
6969
static bool format_is_integer_conv(char c) {
70+
#if SANITIZER_GLIBC
71+
if (char_is_one_of(c, "bB"))
72+
return true;
73+
#endif
7074
return char_is_one_of(c, "diouxXn");
7175
}
7276

compiler-rt/lib/sanitizer_common/tests/sanitizer_format_interceptor_test.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using namespace __sanitizer;
3838
#include "sanitizer_common/sanitizer_common_interceptors_format.inc"
3939

4040
static const unsigned I = sizeof(int);
41+
static const unsigned Z = sizeof(size_t);
4142
static const unsigned L = sizeof(long);
4243
static const unsigned LL = sizeof(long long);
4344
static const unsigned S = sizeof(short);
@@ -113,6 +114,8 @@ static void testScanfNoGnuMalloc(const char *format, unsigned n, ...) {
113114

114115
TEST(SanitizerCommonInterceptors, Scanf) {
115116
testScanf("%d", 1, I);
117+
testScanf("%zx", 1, Z);
118+
testScanf("%zd", 1, Z);
116119
testScanf("%d%d%d", 3, I, I, I);
117120
testScanf("ab%u%dc", 2, I, I);
118121
testScanf("%ld", 1, L);
@@ -128,7 +131,6 @@ TEST(SanitizerCommonInterceptors, Scanf) {
128131
testScanf("a%%%%b", 0);
129132
testScanf("a%%b%%", 0);
130133
testScanf("a%%%%%%b", 0);
131-
testScanf("a%%%%%b", 0);
132134
testScanf("a%%%%%f", 1, F);
133135
testScanf("a%%%lxb", 1, L);
134136
testScanf("a%lf%%%lxb", 2, D, L);
@@ -204,6 +206,14 @@ TEST(SanitizerCommonInterceptors, Scanf) {
204206
testScanfPartial("%d%n%n%d %s %s", 3, 5, I, I, I, I, test_buf_size);
205207
testScanfPartial("%d%n%n%d %s %s", 4, 6, I, I, I, I, test_buf_size,
206208
test_buf_size);
209+
210+
#if defined(__GLIBC__)
211+
testScanf("%b", 1, I);
212+
testScanf("%zb", 1, Z);
213+
testScanf("a%%%%%b", 1, I);
214+
#else
215+
testScanf("a%%%%%b", 0);
216+
#endif
207217
}
208218

209219
TEST(SanitizerCommonInterceptors, ScanfAllocate) {

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_lldb_tool(lldb-dap
2323
Breakpoint.cpp
2424
BreakpointBase.cpp
2525
DAP.cpp
26+
EventHelper.cpp
2627
ExceptionBreakpoint.cpp
2728
FifoFiles.cpp
2829
FunctionBreakpoint.cpp
@@ -36,6 +37,19 @@ add_lldb_tool(lldb-dap
3637
SourceBreakpoint.cpp
3738
Watchpoint.cpp
3839

40+
Handler/AttachRequestHandler.cpp
41+
Handler/BreakpointLocationsHandler.cpp
42+
Handler/CompletionsHandler.cpp
43+
Handler/ConfigurationDoneRequestHandler.cpp
44+
Handler/ContinueRequestHandler.cpp
45+
Handler/DisconnectRequestHandler.cpp
46+
Handler/EvaluateRequestHandler.cpp
47+
Handler/ExceptionInfoRequestHandler.cpp
48+
Handler/InitializeRequestHandler.cpp
49+
Handler/LaunchRequestHandler.cpp
50+
Handler/RequestHandler.cpp
51+
Handler/RestartRequestHandler.cpp
52+
3953
LINK_LIBS
4054
liblldb
4155
lldbHost
@@ -46,6 +60,8 @@ add_lldb_tool(lldb-dap
4660
Support
4761
)
4862

63+
target_include_directories(lldb-dap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
64+
4965
if(LLDB_DAP_WELCOME_MESSAGE)
5066
target_compile_definitions(lldb-dap
5167
PRIVATE

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,25 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
757757
const auto packet_type = GetString(object, "type");
758758
if (packet_type == "request") {
759759
const auto command = GetString(object, "command");
760+
761+
// Try the new request handler first.
762+
auto new_handler_pos = new_request_handlers.find(command);
763+
if (new_handler_pos != new_request_handlers.end()) {
764+
(*new_handler_pos->second)(object);
765+
return true; // Success
766+
}
767+
768+
// FIXME: Remove request_handlers once everything has been migrated.
760769
auto handler_pos = request_handlers.find(command);
761-
if (handler_pos == request_handlers.end()) {
762-
if (log)
763-
*log << "error: unhandled command \"" << command.data() << "\""
764-
<< std::endl;
765-
return false; // Fail
770+
if (handler_pos != request_handlers.end()) {
771+
handler_pos->second(*this, object);
772+
return true; // Success
766773
}
767774

768-
handler_pos->second(*this, object);
769-
return true; // Success
775+
if (log)
776+
*log << "error: unhandled command \"" << command.data() << "\""
777+
<< std::endl;
778+
return false; // Fail
770779
}
771780

772781
if (packet_type == "response") {

lldb/tools/lldb-dap/DAP.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "DAPForward.h"
1313
#include "ExceptionBreakpoint.h"
1414
#include "FunctionBreakpoint.h"
15+
#include "Handler/RequestHandler.h"
1516
#include "IOStream.h"
1617
#include "InstructionBreakpoint.h"
1718
#include "OutputRedirector.h"
@@ -37,6 +38,7 @@
3738
#include "llvm/Support/JSON.h"
3839
#include "llvm/Support/Threading.h"
3940
#include <map>
41+
#include <memory>
4042
#include <mutex>
4143
#include <optional>
4244
#include <thread>
@@ -185,6 +187,7 @@ struct DAP {
185187
lldb::pid_t restarting_process_id;
186188
bool configuration_done_sent;
187189
std::map<std::string, RequestCallback, std::less<>> request_handlers;
190+
llvm::StringMap<std::unique_ptr<RequestHandler>> new_request_handlers;
188191
bool waiting_for_run_in_terminal;
189192
ProgressEventReporter progress_event_reporter;
190193
// Keep track of the last stop thread index IDs as threads won't go away
@@ -342,6 +345,12 @@ struct DAP {
342345
/// IDE.
343346
void RegisterRequestCallback(std::string request, RequestCallback callback);
344347

348+
/// Registers a request handler.
349+
template <typename Handler> void RegisterRequest() {
350+
new_request_handlers[Handler::getCommand()] =
351+
std::make_unique<Handler>(*this);
352+
}
353+
345354
/// Debuggee will continue from stopped state.
346355
void WillContinue() { variables.Clear(); }
347356

0 commit comments

Comments
 (0)