Skip to content

Commit ec5d451

Browse files
committed
Fix MSVC visibility in crash_diagnostic bad_plugins
1 parent 0daccd1 commit ec5d451

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
// Bad plugin #1: crashes during construction (inside allocator).
22
// Simulates a library that segfaults when the app tries to instantiate it.
33

4+
// Bad plugin #1: crashes during construction (inside allocator).
5+
// Simulates a library that segfaults when the app tries to instantiate it.
6+
47
#include <stdexcept>
58

9+
#if defined(_WIN32)
10+
#define BAD_EXPORT __declspec(dllexport)
11+
#else
12+
#define BAD_EXPORT __attribute__((visibility("default")))
13+
#endif
14+
615
class CrashInConstructor {
716
public:
817
CrashInConstructor() {
@@ -11,9 +20,6 @@ class CrashInConstructor {
1120
};
1221

1322
extern "C" {
14-
__attribute__((visibility("default")))
15-
CrashInConstructor* allocator() { return new CrashInConstructor(); }
16-
17-
__attribute__((visibility("default")))
18-
void deallocator(CrashInConstructor* ptr) { delete ptr; }
23+
BAD_EXPORT CrashInConstructor* allocator() { return new CrashInConstructor(); }
24+
BAD_EXPORT void deallocator(CrashInConstructor* ptr) { delete ptr; }
1925
}

examples/crash_diagnostic/bad_plugins/crash_on_load.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
// A global/static constructor runs during library loading and fails.
33
// This is the hardest to debug because it happens inside dlopen() itself.
44

5+
// Bad plugin #3: crashes at dlopen time, before any symbol is resolved.
6+
// A global/static constructor runs during library loading and fails.
7+
58
#include <stdexcept>
69

10+
#if defined(_WIN32)
11+
#define BAD_EXPORT __declspec(dllexport)
12+
#else
13+
#define BAD_EXPORT __attribute__((visibility("default")))
14+
#endif
15+
716
static int bad_init() {
817
throw std::runtime_error("static init failed: cannot connect to server");
918
return 0;
@@ -18,9 +27,6 @@ class CrashOnLoad {
1827
};
1928

2029
extern "C" {
21-
__attribute__((visibility("default")))
22-
CrashOnLoad* allocator() { return new CrashOnLoad(); }
23-
24-
__attribute__((visibility("default")))
25-
void deallocator(CrashOnLoad* ptr) { delete ptr; }
30+
BAD_EXPORT CrashOnLoad* allocator() { return new CrashOnLoad(); }
31+
BAD_EXPORT void deallocator(CrashOnLoad* ptr) { delete ptr; }
2632
}

0 commit comments

Comments
 (0)