Skip to content

Commit 3d2376f

Browse files
committed
Increase native test coverage and add fuzzing
1 parent 996bcbf commit 3d2376f

35 files changed

+3827
-15
lines changed

.github/scripts/prepare_reports.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ cp ddprof-test/build/hs_err* reports/ || true
88
cp -r ddprof-lib/build/tmp reports/native_build || true
99
cp -r ddprof-test/build/reports/tests reports/tests || true
1010
cp -r /tmp/recordings reports/recordings || true
11+
cp -r ddprof-lib/gtest/build/tmp reports/gtest || true
1112
find ddprof-lib/build -name 'libjavaProfiler.*' -exec cp {} reports/ \; || true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TARGET_DIR = ../build/test/resources/native-libs/reladyn-lib
2+
all:
3+
g++ -fPIC -shared -o $(TARGET_DIR)/libreladyn.so reladyn.c
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The async-profiler authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
#include <pthread.h>
6+
#include <stdio.h>
7+
// Force pthread_setspecific into .rela.dyn with R_X86_64_GLOB_DAT.
8+
int (*indirect_pthread_setspecific)(pthread_key_t, const void*);
9+
// Force pthread_exit into .rela.dyn with R_X86_64_64.
10+
void (*static_pthread_exit)(void*) = pthread_exit;
11+
void* thread_function(void* arg) {
12+
printf("Thread running\n");
13+
return NULL;
14+
}
15+
// Not indended to be executed.
16+
int reladyn() {
17+
pthread_t thread;
18+
pthread_key_t key;
19+
pthread_key_create(&key, NULL);
20+
// Direct call, forces into .rela.plt.
21+
pthread_create(&thread, NULL, thread_function, NULL);
22+
// Assign to a function pointer at runtime, forces into .rela.dyn as R_X86_64_GLOB_DAT.
23+
indirect_pthread_setspecific = pthread_setspecific;
24+
indirect_pthread_setspecific(key, "Thread-specific value");
25+
// Use pthread_exit via the static pointer, forces into .rela.dyn as R_X86_64_64.
26+
static_pthread_exit(NULL);
27+
return 0;
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TARGET_DIR = ../build/test/resources/native-libs/small-lib
2+
all:
3+
g++ -fPIC -shared -o $(TARGET_DIR)/libsmall-lib.so small_lib.cpp
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
#include "small_lib.h"
3+
4+
extern "C" void hello() {
5+
std::cout << "Hello, World from shared library!" << std::endl;
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
extern "C" {
4+
void hello();
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TARGET_DIR = ../build/test/resources/unresolved-functions
2+
all:
3+
gcc -c main.c -o $(TARGET_DIR)/main.o
4+
gcc -o $(TARGET_DIR)/main $(TARGET_DIR)/main.o -T linker.ld
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
PHDRS
2+
{
3+
headers PT_PHDR PHDRS ;
4+
interp PT_INTERP ;
5+
text PT_LOAD FILEHDR PHDRS ;
6+
data PT_LOAD ;
7+
}
8+
9+
SECTIONS
10+
{
11+
. = 0x10000;
12+
.text : {
13+
*(.text)
14+
} :text
15+
16+
. = 0x20000;
17+
.data : {
18+
*(.data)
19+
} :data
20+
21+
.bss : {
22+
*(.bss)
23+
}
24+
25+
. = 0x30000;
26+
unresolved_symbol = .;
27+
. = 0xffffffffffffffff;
28+
unresolved_function = .;
29+
30+
/* Add the .init_array section */
31+
.init_array : {
32+
__init_array_start = .;
33+
KEEP(*(.init_array))
34+
__init_array_end = .;
35+
}
36+
37+
/* Add the .fini_array section */
38+
.fini_array : {
39+
__fini_array_start = .;
40+
KEEP(*(.fini_array))
41+
__fini_array_end = .;
42+
}
43+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
extern int unresolved_symbol;
4+
extern int unresolved_function();
5+
6+
int main() {
7+
printf("Value of unresolved_symbol: %p\n", &unresolved_symbol);
8+
printf("Value of unresolved_function: %p\n", &unresolved_function);
9+
return 0;
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Description
2+
3+
This binary tests that we are able to parse symbols even when they point to unresolved functions.
4+
The function is set to point to a 0xffffffffffffffff address.

0 commit comments

Comments
 (0)