forked from libbpf/blazesym
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an end-to-end test for the fix provided by pull request libbpf#875. The test basically normalizes an address in a specially crafted binary and symbolizes the resulting file offset. It fails without commit 1a4e107 ("Use file size in file offset -> virtual offset translation"), because then the file offset to virtual offset translation produces a virtual offset that can't be symbolized to the expected _start function. For the record, the binary looks roughly as follows: $ readelf --segments --wide test-block.bin > Program Headers: > Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align > LOAD 0x000000 0x00000000000ff000 0x00000000000ff000 0x0001c8 0x301000 RW 0x1000 > LOAD 0x0001c8 0x00000000004001c8 0x00000000004001c8 0x000030 0x000030 R 0x1000 > LOAD 0x001000 0x0000000000401000 0x0000000000401000 0x00005b 0x00005b R E 0x1000 > LOAD 0x002000 0x0000000000402000 0x0000000000402000 0x000038 0x000038 R 0x1000 > [...] Signed-off-by: Daniel Müller <deso@posteo.net>
- Loading branch information
1 parent
1155849
commit cfd540c
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Linker script meant to augment the default one and insert some | ||
* fill bytes at a relatively low address (hopefully before any of the | ||
* regular relevant code. */ | ||
|
||
SECTIONS { | ||
.whatevs (0x100000): { | ||
FILL(0xdead) | ||
. = ABSOLUTE(. + 0x300000); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* A binary basically just blocking waiting for input and exiting. It also write | ||
* the address of its `_start` function to stdout (unformatted; just a byte | ||
* dump). | ||
* | ||
* It uses raw system calls to avoid dependency on libc, which pulls in | ||
* start up code and various other artifacts that perturb ELF layout in | ||
* semi-unforeseeable ways, in an attempt to provide us with maximum | ||
* control over the final binary. | ||
* | ||
* Likely only works on x86_64. | ||
*/ | ||
|
||
#include <unistd.h> | ||
#include <sys/syscall.h> | ||
|
||
|
||
void _start(void) { | ||
char buf[2]; | ||
int rc; | ||
void* addr = (void*)&_start; | ||
/* Write the address of `_start` to stderr. We use stderr because it's | ||
unbuffered, so we spare ourselves from the pains of writing a | ||
newline as well... */ | ||
asm volatile ( | ||
"syscall" | ||
: "=a"(rc) | ||
: "a"(SYS_write), "D"(STDERR_FILENO), "S"(&addr), "d"(sizeof(addr)) | ||
: "rcx", "r11", "memory" | ||
); | ||
asm volatile ( | ||
"syscall" | ||
: "=a"(rc) | ||
: "a"(SYS_read), "D"(STDIN_FILENO), "S"(buf), "d"(sizeof(buf)) | ||
: "rcx", "r11", "memory" | ||
); | ||
if (rc > 0) { | ||
/* No error, so we can exit successfully. */ | ||
rc = 0; | ||
} | ||
asm volatile ( | ||
"syscall" | ||
: "=a"(rc) | ||
: "a"(SYS_exit), "D"(rc) | ||
: "rcx", "r11", "memory" | ||
); | ||
} |
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
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