Skip to content

Commit 6601591

Browse files
AutomergerAutomerger
authored andcommitted
Propagating prior merge from 'llvm.org/master'.
apple-llvm-split-commit: a8ea9991a6b6d71ca12bc7bdae154e2db626b553 apple-llvm-split-dir: compiler-rt/
2 parents 5946054 + 6371911 commit 6601591

File tree

30 files changed

+1278
-853
lines changed

30 files changed

+1278
-853
lines changed

compiler-rt/lib/interception/interception_linux.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int StrCmp(const char *s1, const char *s2) {
3333
}
3434
#endif
3535

36-
static void *GetFuncAddr(const char *name) {
36+
static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
3737
#if SANITIZER_NETBSD
3838
// FIXME: Find a better way to handle renames
3939
if (StrCmp(name, "sigaction"))
@@ -47,13 +47,18 @@ static void *GetFuncAddr(const char *name) {
4747
// want the address of the real definition, though, so look it up using
4848
// RTLD_DEFAULT.
4949
addr = dlsym(RTLD_DEFAULT, name);
50+
51+
// In case `name' is not loaded, dlsym ends up finding the actual wrapper.
52+
// We don't want to intercept the wrapper and have it point to itself.
53+
if ((uptr)addr == wrapper_addr)
54+
addr = nullptr;
5055
}
5156
return addr;
5257
}
5358

5459
bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
5560
uptr wrapper) {
56-
void *addr = GetFuncAddr(name);
61+
void *addr = GetFuncAddr(name, wrapper);
5762
*ptr_to_real = (uptr)addr;
5863
return addr && (func == wrapper);
5964
}

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,8 @@ INTERCEPTOR_WITH_SUFFIX(int, fputs, char *s, void *file) {
12411241
// libc file streams can call user-supplied functions, see fopencookie.
12421242
void *ctx;
12431243
COMMON_INTERCEPTOR_ENTER(ctx, fputs, s, file);
1244-
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1244+
if (!SANITIZER_MAC || s)
1245+
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
12451246
return REAL(fputs)(s, file);
12461247
}
12471248
#define INIT_FPUTS COMMON_INTERCEPT_FUNCTION(fputs)
@@ -1254,7 +1255,8 @@ INTERCEPTOR(int, puts, char *s) {
12541255
// libc file streams can call user-supplied functions, see fopencookie.
12551256
void *ctx;
12561257
COMMON_INTERCEPTOR_ENTER(ctx, puts, s);
1257-
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
1258+
if (!SANITIZER_MAC || s)
1259+
COMMON_INTERCEPTOR_READ_RANGE(ctx, s, REAL(strlen)(s) + 1);
12581260
return REAL(puts)(s);
12591261
}
12601262
#define INIT_PUTS COMMON_INTERCEPT_FUNCTION(puts)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %clangxx_asan -xc++ -shared -fPIC -o %t.so - < %s
2+
// RUN: %clang_asan %s -o %t.out -ldl
3+
// RUN: ASAN_OPTIONS=verbosity=1 not %t.out %t.so 2>&1 | FileCheck %s
4+
//
5+
// CHECK: AddressSanitizer: failed to intercept '__cxa_throw'
6+
//
7+
// dlopen() can not be intercepted on Android
8+
// UNSUPPORTED: android
9+
#ifdef __cplusplus
10+
11+
static void foo(void) {
12+
int i = 0;
13+
throw(i);
14+
}
15+
16+
extern "C" {
17+
int bar(void);
18+
};
19+
int bar(void) {
20+
try {
21+
foo();
22+
} catch (int i) {
23+
return i;
24+
}
25+
return -1;
26+
}
27+
28+
#else
29+
30+
#include <assert.h>
31+
#include <dlfcn.h>
32+
33+
int main(int argc, char **argv) {
34+
int (*bar)(void);
35+
void *handle = dlopen(argv[1], RTLD_LAZY);
36+
assert(handle);
37+
bar = dlsym(handle, "bar");
38+
assert(bar);
39+
return bar();
40+
}
41+
42+
#endif

compiler-rt/test/hwasan/TestCases/cfi.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_hwasan -fsanitize=cfi -fno-sanitize-trap=cfi -flto -fvisibility=hidden -fuse-ld=lld %s -o %t
1+
// RUN: %clangxx_hwasan -fsanitize=cfi -fno-sanitize-trap=cfi -flto -fvisibility=hidden -fuse-ld=lld %s -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33

44
// REQUIRES: android
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// On Darwin, the man page states that "both fputs() and puts() print `(null)'
2+
// if str is NULL."
3+
//
4+
// RUN: %clangxx -g %s -o %t && %run %t | FileCheck %s
5+
// CHECK: {{^\(null\)---\(null\)$}}
6+
7+
#include <assert.h>
8+
#include <stdio.h>
9+
10+
int main(void) {
11+
assert(fputs(NULL, stdout) >= 0);
12+
fputs("---", stdout);
13+
assert(puts(NULL) >= 0);
14+
15+
return 0;
16+
}

lld/ELF/DWARF.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ LLDDwarfObj<ELFT>::findAux(const InputSectionBase &sec, uint64_t pos,
110110
DataRefImpl d;
111111
d.p = getAddend<ELFT>(rel);
112112
return RelocAddrEntry{secIndex, RelocationRef(d, nullptr),
113-
LLDRelocationResolver<RelTy>::resolve, val};
113+
val, Optional<object::RelocationRef>(),
114+
0, LLDRelocationResolver<RelTy>::resolve};
114115
}
115116

116117
template <class ELFT>

lld/test/ELF/basic32.s renamed to lld/test/ELF/basic-i386.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t
3-
# RUN: ld.lld %t -o %t2
4-
# RUN: llvm-readobj --file-headers --sections -l %t2 | FileCheck %s
2+
# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
3+
# RUN: ld.lld %t.o -o %t
4+
# RUN: llvm-readobj --file-headers --sections -l %t | FileCheck %s
55

66
# exits with return code 42 on linux
77
.globl _start

lld/test/ELF/basic-ppc64.s

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# REQUIRES: ppc
2-
# # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t
3-
# RUN: ld.lld --hash-style=sysv -discard-all -shared %t -o %t2
4-
# RUN: llvm-readobj --file-headers --sections --section-data -l %t2 | FileCheck %s
2+
# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
3+
# RUN: ld.lld --hash-style=sysv -discard-all -shared %t.o -o %t.so
4+
# RUN: llvm-readobj --file-headers --sections --section-data -l %t.so | FileCheck --check-prefixes=CHECK,LE %s
5+
6+
# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
7+
# RUN: ld.lld --hash-style=sysv -discard-all -shared %t.o -o %t.so
8+
# RUN: llvm-readobj --file-headers --sections --section-data -l %t.so | FileCheck --check-prefixes=CHECK,BE %s
9+
510
.abiversion 2
611
# Exits with return code 55 on linux.
712
.text
@@ -10,14 +15,16 @@
1015
sc
1116

1217
// CHECK:Format: ELF64-ppc64
13-
// CHECK-NEXT:Arch: powerpc64le
14-
// CHECK-NEXT:AddressSize: 64bit
15-
// CHECK-NEXT:LoadName:
16-
// CHECK-NEXT:ElfHeader {
18+
// LE-NEXT: Arch: powerpc64le
19+
// BE-NEXT: Arch: powerpc64{{$}}
20+
// CHECK-NEXT: AddressSize: 64bit
21+
// CHECK-NEXT: LoadName:
22+
// CHECK-NEXT: ElfHeader {
1723
// CHECK-NEXT: Ident {
1824
// CHECK-NEXT: Magic: (7F 45 4C 46)
1925
// CHECK-NEXT: Class: 64-bit (0x2)
20-
// CHECK-NEXT: DataEncoding: LittleEndian (0x1)
26+
// LE-NEXT: DataEncoding: LittleEndian (0x1)
27+
// BE-NEXT: DataEncoding: BigEndian (0x2)
2128
// CHECK-NEXT: FileVersion: 1
2229
// CHECK-NEXT: OS/ABI: SystemV (0x0)
2330
// CHECK-NEXT: ABIVersion: 0
@@ -90,7 +97,8 @@
9097
// CHECK-NEXT: AddressAlignment: 4
9198
// CHECK-NEXT: EntrySize: 4
9299
// CHECK-NEXT: SectionData (
93-
// CHECK-NEXT: 0000: 01000000 01000000 00000000 00000000 |................|
100+
// LE-NEXT: 0000: 01000000 01000000 00000000 00000000
101+
// BE-NEXT: 0000: 00000001 00000001 00000000 00000000
94102
// CHECK-NEXT: )
95103
// CHECK-NEXT: }
96104
// CHECK-NEXT: Section {
@@ -127,7 +135,8 @@
127135
// CHECK-NEXT: AddressAlignment: 4
128136
// CHECK-NEXT: EntrySize: 0
129137
// CHECK-NEXT: SectionData (
130-
// CHECK-NEXT: 0000: 01000038 37006038 02000044 |...87.`8...D|
138+
// LE-NEXT: 0000: 01000038 37006038 02000044
139+
// BE-NEXT: 0000: 38000001 38600037 44000002
131140
// CHECK-NEXT: )
132141
// CHECK-NEXT: }
133142
// CHECK-NEXT: Section {
@@ -146,12 +155,18 @@
146155
// CHECK-NEXT: AddressAlignment: 8
147156
// CHECK-NEXT: EntrySize: 16
148157
// CHECK-NEXT: SectionData (
149-
// CHECK-NEXT: 0000: 06000000 00000000 00020000 00000000 |
150-
// CHECK-NEXT: 0010: 0B000000 00000000 18000000 00000000 |
151-
// CHECK-NEXT: 0020: 05000000 00000000 28020000 00000000 |
152-
// CHECK-NEXT: 0030: 0A000000 00000000 01000000 00000000 |
153-
// CHECK-NEXT: 0040: 04000000 00000000 18020000 00000000 |
154-
// CHECK-NEXT: 0050: 00000000 00000000 00000000 00000000 |
158+
// LE-NEXT: 0000: 06000000 00000000 00020000 00000000 |
159+
// LE-NEXT: 0010: 0B000000 00000000 18000000 00000000 |
160+
// LE-NEXT: 0020: 05000000 00000000 28020000 00000000 |
161+
// LE-NEXT: 0030: 0A000000 00000000 01000000 00000000 |
162+
// LE-NEXT: 0040: 04000000 00000000 18020000 00000000 |
163+
// LE-NEXT: 0050: 00000000 00000000 00000000 00000000 |
164+
// BE-NEXT: 0000: 00000000 00000006 00000000 00000200 |
165+
// BE-NEXT: 0010: 00000000 0000000B 00000000 00000018 |
166+
// BE-NEXT: 0020: 00000000 00000005 00000000 00000228 |
167+
// BE-NEXT: 0030: 00000000 0000000A 00000000 00000001 |
168+
// BE-NEXT: 0040: 00000000 00000004 00000000 00000218 |
169+
// BE-NEXT: 0050: 00000000 00000000 00000000 00000000 |
155170
// CHECK-NEXT: )
156171
// CHECK-NEXT: }
157172
// CHECK-NEXT: Section {
@@ -203,9 +218,12 @@
203218
// CHECK-NEXT: AddressAlignment: 8
204219
// CHECK-NEXT: EntrySize: 24
205220
// CHECK-NEXT: SectionData (
206-
// CHECK-NEXT: 0000: 00000000 00000000 00000000 00000000 |................|
207-
// CHECK-NEXT: 0010: 00000000 00000000 01000000 00020500 |................|
208-
// CHECK-NEXT: 0020: 00000200 00000000 00000000 00000000 |................|
221+
// LE-NEXT: 0000: 00000000 00000000 00000000 00000000 |................|
222+
// LE-NEXT: 0010: 00000000 00000000 01000000 00020500 |................|
223+
// LE-NEXT: 0020: 00000200 00000000 00000000 00000000 |................|
224+
// BE-NEXT: 0000: 00000000 00000000 00000000 00000000 |................|
225+
// BE-NEXT: 0010: 00000000 00000000 00000001 00020005 |................|
226+
// BE-NEXT: 0020: 00000000 00020000 00000000 00000000 |................|
209227
// CHECK-NEXT: )
210228
// CHECK-NEXT: }
211229
// CHECK-NEXT: Section {

0 commit comments

Comments
 (0)