-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: code in non-executable ELF sections
- Loading branch information
1 parent
c85efac
commit e4d874d
Showing
4 changed files
with
45 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Previously in TinyCC, ELF sections defined in assembly would always have the | ||
execute bit not set, so you would get segmentation faults when code in these | ||
sections was exectuted. This file is a minimal example of a file that will put | ||
the resulting code in a non-executable section (and invoke it) prior to the fix. | ||
*/ | ||
#include <stdio.h> | ||
|
||
void *memset(void *dst, int c, int len); | ||
|
||
__asm__ ( | ||
".section .text.nolibc_memset\n" | ||
".weak memset\n" | ||
"memset:\n" | ||
"xchgl %eax, %esi\n\t" | ||
"movq %rdx, %rcx\n\t" | ||
"pushq %rdi\n\t" | ||
"rep stosb\n\t" | ||
"popq %rax\n\t" | ||
"retq\n" | ||
); | ||
|
||
int main () { | ||
char buf[10]; | ||
memset(&buf[0], 'A', 9); | ||
buf[9] = 0; | ||
puts(buf); | ||
return 0; | ||
} |
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,13 @@ | ||
/* Previously in TinyCC, ELF sections defined in attributes would always have | ||
the execute bit not set, so you would get segmentation faults when code in these | ||
sections was exectuted. This file is a minimal example of a file that will put | ||
the resulting code in a non-executable section (and invoke it) prior to the fix. | ||
*/ | ||
__attribute__((section(".text.wumbo"))) | ||
int wumbo (int arg) { | ||
return arg * 2; | ||
} | ||
|
||
int main () { | ||
return wumbo(2); | ||
} |