Skip to content

Commit af098e0

Browse files
authored
Revert "[ubsan_minimal] Allow UBSan handler from Minimal runtime to accept arguments (#152192)" (#168812)
This partially reverts #152192, keeping updated tests and some code reordering in clang/lib/CodeGen/CGExpr.cpp. compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp is exact revert (with followup #152419) We don't have a good use case for that, so revert it before we are stuck maintaining this API. 21.x does not have this patch. This reverts commit a1209d8.
1 parent 8b7c495 commit af098e0

File tree

4 files changed

+17
-53
lines changed

4 files changed

+17
-53
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,18 +3900,8 @@ void CodeGenFunction::EmitCheck(
39003900

39013901
// Clear arguments for the MinimalRuntime handler.
39023902
if (CGM.getCodeGenOpts().SanitizeMinimalRuntime) {
3903-
switch (CheckHandler) {
3904-
case SanitizerHandler::TypeMismatch:
3905-
// Pass value pointer only. It adds minimal overhead.
3906-
StaticArgs = {};
3907-
assert(DynamicArgs.size() == 1);
3908-
break;
3909-
default:
3910-
// No arguments for other checks.
3911-
StaticArgs = {};
3912-
DynamicArgs = {};
3913-
break;
3914-
}
3903+
StaticArgs = {};
3904+
DynamicArgs = {};
39153905
}
39163906

39173907
// Handler functions take an i8* pointing to the (handler-specific) static

compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,20 @@ static char *append_hex(uintptr_t d, char *buf, const char *end) {
3434
return buf;
3535
}
3636

37-
static void format_msg(const char *kind, uintptr_t caller,
38-
const uintptr_t *address, char *buf, const char *end) {
37+
static void format_msg(const char *kind, uintptr_t caller, char *buf,
38+
const char *end) {
3939
buf = append_str("ubsan: ", buf, end);
4040
buf = append_str(kind, buf, end);
4141
buf = append_str(" by 0x", buf, end);
4242
buf = append_hex(caller, buf, end);
43-
if (address) {
44-
buf = append_str(" address 0x", buf, end);
45-
buf = append_hex(*address, buf, end);
46-
}
4743
buf = append_str("\n", buf, end);
4844
if (buf == end)
4945
--buf; // Make sure we don't cause a buffer overflow.
5046
*buf = '\0';
5147
}
5248

5349
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
54-
uintptr_t caller, const uintptr_t *address) {
50+
uintptr_t caller) {
5551
if (caller == 0)
5652
return;
5753
while (true) {
@@ -84,32 +80,28 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error, const char *kind,
8480
__sanitizer::atomic_store_relaxed(&caller_pcs[sz], caller);
8581

8682
char msg_buf[128];
87-
format_msg(kind, caller, address, msg_buf, msg_buf + sizeof(msg_buf));
83+
format_msg(kind, caller, msg_buf, msg_buf + sizeof(msg_buf));
8884
message(msg_buf);
8985
}
9086
}
9187

9288
SANITIZER_INTERFACE_WEAK_DEF(void, __ubsan_report_error_fatal, const char *kind,
93-
uintptr_t caller, const uintptr_t *address) {
89+
uintptr_t caller) {
9490
// Use another handlers, in case it's already overriden.
95-
__ubsan_report_error(kind, caller, address);
91+
__ubsan_report_error(kind, caller);
9692
}
9793

9894
#if defined(__ANDROID__)
9995
extern "C" __attribute__((weak)) void android_set_abort_message(const char *);
100-
static void abort_with_message(const char *kind, uintptr_t caller,
101-
const uintptr_t *address) {
96+
static void abort_with_message(const char *kind, uintptr_t caller) {
10297
char msg_buf[128];
103-
format_msg(kind, caller, address, msg_buf, msg_buf + sizeof(msg_buf));
98+
format_msg(kind, caller, msg_buf, msg_buf + sizeof(msg_buf));
10499
if (&android_set_abort_message)
105100
android_set_abort_message(msg_buf);
106101
abort();
107102
}
108103
#else
109-
static void abort_with_message(const char *kind, uintptr_t caller,
110-
const uintptr_t *address) {
111-
abort();
112-
}
104+
static void abort_with_message(const char *kind, uintptr_t caller) { abort(); }
113105
#endif
114106

115107
#if SANITIZER_DEBUG
@@ -129,39 +121,21 @@ void NORETURN CheckFailed(const char *file, int, const char *cond, u64, u64) {
129121

130122
#define HANDLER_RECOVER(name, kind) \
131123
INTERFACE void __ubsan_handle_##name##_minimal() { \
132-
__ubsan_report_error(kind, GET_CALLER_PC(), nullptr); \
124+
__ubsan_report_error(kind, GET_CALLER_PC()); \
133125
}
134126

135127
#define HANDLER_NORECOVER(name, kind) \
136128
INTERFACE void __ubsan_handle_##name##_minimal_abort() { \
137129
uintptr_t caller = GET_CALLER_PC(); \
138-
__ubsan_report_error_fatal(kind, caller, nullptr); \
139-
abort_with_message(kind, caller, nullptr); \
130+
__ubsan_report_error_fatal(kind, caller); \
131+
abort_with_message(kind, caller); \
140132
}
141133

142134
#define HANDLER(name, kind) \
143135
HANDLER_RECOVER(name, kind) \
144136
HANDLER_NORECOVER(name, kind)
145137

146-
#define HANDLER_RECOVER_PTR(name, kind) \
147-
INTERFACE void __ubsan_handle_##name##_minimal(const uintptr_t address) { \
148-
__ubsan_report_error(kind, GET_CALLER_PC(), &address); \
149-
}
150-
151-
#define HANDLER_NORECOVER_PTR(name, kind) \
152-
INTERFACE void __ubsan_handle_##name##_minimal_abort( \
153-
const uintptr_t address) { \
154-
uintptr_t caller = GET_CALLER_PC(); \
155-
__ubsan_report_error_fatal(kind, caller, &address); \
156-
abort_with_message(kind, caller, &address); \
157-
}
158-
159-
// A version of a handler that takes a pointer to a value.
160-
#define HANDLER_PTR(name, kind) \
161-
HANDLER_RECOVER_PTR(name, kind) \
162-
HANDLER_NORECOVER_PTR(name, kind)
163-
164-
HANDLER_PTR(type_mismatch, "type-mismatch")
138+
HANDLER(type_mismatch, "type-mismatch")
165139
HANDLER(alignment_assumption, "alignment-assumption")
166140
HANDLER(add_overflow, "add-overflow")
167141
HANDLER(sub_overflow, "sub-overflow")

compiler-rt/test/ubsan_minimal/TestCases/misalignment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int *t;
77
int main() {
88
int r;
99
t = (int *)(((char *)&r) + 1);
10-
// CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}} address 0x{{[[:xdigit:]]+$}}
10+
// CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}}
1111
// CHECK-NOT: type-mismatch
1212
f(*t);
1313
}

compiler-rt/test/ubsan_minimal/TestCases/null.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void f(int &n) {}
55
int *t;
66

77
int main() {
8-
// CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}} address 0x{{[[:xdigit:]]+$}}
8+
// CHECK: ubsan: type-mismatch by 0x{{[[:xdigit:]]+}}
99
// CHECK-NOT: type-mismatch
1010
f(*t);
1111
}

0 commit comments

Comments
 (0)