fix: previous two commits
[tinycc.git] / tests / tests2 / 133_exec_section_in_asm.c
blob8f13a418c1375efd102d92387c065dd0068518d0
1 /* Previously in TinyCC, ELF sections defined in assembly would always have the
2 execute bit not set, so you would get segmentation faults when code in these
3 sections was exectuted. This file is a minimal example of a file that will put
4 the resulting code in a non-executable section (and invoke it) prior to the fix.
5 */
6 #include <stdio.h>
8 void *memset(void *dst, int c, int len);
10 __asm__ (
11 ".section .text.nolibc_memset\n"
12 ".weak memset\n"
13 "memset:\n"
14 "xchgl %eax, %esi\n\t"
15 "movq %rdx, %rcx\n\t"
16 "pushq %rdi\n\t"
17 "rep stosb\n\t"
18 "popq %rax\n\t"
19 "retq\n"
22 int main () {
23 char buf[10];
24 memset(&buf[0], 'A', 9);
25 buf[9] = 0;
26 puts(buf);
27 return 0;