Skip to content

Commit

Permalink
New method for running AddressSanitizer
Browse files Browse the repository at this point in the history
Old method broke after some CS2 update, because Valve started passing RTLD_DEEPBIND to dlopen themselves. So we have to override all dlopen calls to remove the flag.

Credit to Poggu for coming up with dlhook
  • Loading branch information
Vauff committed Oct 19, 2024
1 parent f28de64 commit 58a3c49
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
help="Override the target architecture (use commas to separate multiple targets).")
# AddressSanitizer Instructions:
# Recompile Metamod with RTLD_DEEPBIND removed (may break some std functionality)
# Run server with LD_PRELOAD=/usr/lib/clang/11/lib/linux/libclang_rt.asan-x86_64.so (for SteamRT3)
# Copy devtools/dlhook/libasan.so.dlhook.so to the server
# Run server with LD_PRELOAD="/path/to/libasan.so.dlhook.so /usr/lib/clang/11/lib/linux/libclang_rt.asan-x86_64.so" (for SteamRT3)
# Note this may break some std functionality
parser.options.add_argument('--asan', action='store_const', const='1', dest='asan',
help='Build for AddressSanitizer')
parser.Configure()
Binary file added devtools/dlhook/libasan.so.dlhook.so
Binary file not shown.
1 change: 1 addition & 0 deletions devtools/dlhook/src/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gcc -fPIC -rdynamic -shared dlhook.c -o libasan.so.dlhook.so
15 changes: 15 additions & 0 deletions devtools/dlhook/src/dlhook.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>

void *dlopen(const char *filename, int flags)
{
printf("CALLED DLOPEN!!\n");
typedef void *(*dlopen_t)(const char *filename, int flags);
static dlopen_t func;

if(!func)
func = (dlopen_t)dlsym(RTLD_NEXT, "dlopen");

return(func(filename, flags & ~RTLD_DEEPBIND));
}

0 comments on commit 58a3c49

Please sign in to comment.