Created
June 26, 2021 01:00
-
-
Save rprichard/0518ea05b227d03b749a8128d2649e5f to your computer and use it in GitHub Desktop.
lldb-bugs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cat >dso1.c <<EOF | |
#include <stdio.h> | |
void foo(void) { | |
printf("foo"); | |
printf("\n"); | |
} | |
EOF | |
cat >dso2.c <<EOF | |
#include <stdio.h> | |
void bar(void) { | |
printf("bar"); | |
printf("\n"); | |
} | |
EOF | |
cat >main.c <<EOF | |
#include <assert.h> | |
#include <dlfcn.h> | |
void foo(void); | |
void* not_dlopen(const char* path, int flags) { | |
return (void*)0; | |
} | |
int main() { | |
void* dso2; | |
// Demonstrate bugs in LLDB 12: | |
// - With musl-gcc, stepping over foo() doesn't work: | |
// step over failed (Could not create return address breakpoint. Return | |
// address (0x7fffffffdde8) did not point to executable memory.) | |
// - With gcc or clang (glibc), when stepping over a dlopen call that loads | |
// a library (i.e. the second call), the program doesn't stop and instead | |
// runs to completion. | |
foo(); | |
dso2 = dlopen("libdso2.so", RTLD_NOW | RTLD_LOCAL | RTLD_NOLOAD); | |
dso2 = dlopen("libdso2.so", RTLD_NOW | RTLD_LOCAL); | |
dso2 = dlopen("libdso2.so", RTLD_NOW | RTLD_LOCAL); | |
void (*bar)(void) = dlsym(dso2, "bar"); | |
assert(bar); | |
bar(); | |
return 0; | |
} | |
EOF | |
CC=musl-gcc | |
#CC=clang | |
DL= | |
#DL=-ldl | |
$CC -g dso1.c -fpic -shared -o libdso1.so | |
$CC -g dso2.c -fpic -shared -o libdso2.so | |
$CC -g main.c libdso1.so -o main $DL -Wl,-rpath,'$ORIGIN' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment