Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorBartosz Taudul <wolf.pld@gmail.com>2019-09-27 01:05:41 +0300
committerBartosz Taudul <wolf.pld@gmail.com>2019-09-27 01:05:41 +0300
commit6094d694798b43230abe33b1f3c190add6c134ae (patch)
tree9360df84bb2e7e5f7df8caddea6cdbcb44ecf9e2 /extra
parent9de2d312a3eeea3523bb71f040eca702cc508865 (diff)
Manually load required symbols.
Diffstat (limited to 'extra')
-rw-r--r--extra/systrace/build2
-rw-r--r--extra/systrace/tracy_systrace.c29
2 files changed, 24 insertions, 7 deletions
diff --git a/extra/systrace/build b/extra/systrace/build
index c023ffc8..d3578d15 100644
--- a/extra/systrace/build
+++ b/extra/systrace/build
@@ -1,3 +1,3 @@
-clang tracy_systrace.c -s -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-stack-protector -Wl,-z,norelro -Wl,--build-id=none -nostdlib -lc
+clang tracy_systrace.c -s -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-stack-protector -Wl,-z,norelro -Wl,--build-id=none -nostdlib -ldl
strip --strip-all -R .note.gnu.gold-version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag -R .eh_frame -R .eh_frame_hdr -R .gnu.hash -R .gnu.version -R .got a.out
sstrip -z a.out (elfkickers)
diff --git a/extra/systrace/tracy_systrace.c b/extra/systrace/tracy_systrace.c
index 56b7df49..530f05f5 100644
--- a/extra/systrace/tracy_systrace.c
+++ b/extra/systrace/tracy_systrace.c
@@ -6,15 +6,32 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
+#include <dlfcn.h>
enum { BufSize = 64*1024 };
+typedef int (*open_t)( const char*, int, ... );
+typedef void (*exit_t)( int );
+typedef int (*poll_t)( struct pollfd*, nfds_t, int timeout );
+typedef int (*nanosleep_t)( const struct timespec*, struct timespec* );
+typedef ssize_t (*read_t)( int, void*, size_t );
+typedef ssize_t (*write_t)( int, const void*, size_t );
+
void _start()
{
+ void* libc = dlopen( "libc.so", RTLD_LAZY );
+
+ open_t sym_open = dlsym( libc, "open" );
+ exit_t sym_exit = dlsym( libc, "exit" );
+ poll_t sym_poll = dlsym( libc, "poll" );
+ nanosleep_t sym_nanosleep = dlsym( libc, "nanosleep" );
+ read_t sym_read = dlsym( libc, "read" );
+ write_t sym_write = dlsym( libc, "write" );
+
char buf[BufSize];
- int kernelFd = open( "/sys/kernel/debug/tracing/trace_pipe", O_RDONLY );
- if( kernelFd < 0 ) exit( 0 );
+ int kernelFd = sym_open( "/sys/kernel/debug/tracing/trace_pipe", O_RDONLY );
+ if( kernelFd < 0 ) sym_exit( 0 );
struct pollfd pfd;
pfd.fd = kernelFd;
@@ -26,11 +43,11 @@ void _start()
for(;;)
{
- while( poll( &pfd, 1, 0 ) <= 0 ) nanosleep( &sleepTime, NULL );
- const int rd = read( kernelFd, buf, BufSize );
+ while( sym_poll( &pfd, 1, 0 ) <= 0 ) sym_nanosleep( &sleepTime, NULL );
+ const int rd = sym_read( kernelFd, buf, BufSize );
if( rd <= 0 ) break;
- write( STDOUT_FILENO, buf, rd );
+ sym_write( STDOUT_FILENO, buf, rd );
}
- exit( 0 );
+ sym_exit( 0 );
}