Unified · Split
| @@ -893,6 +893,9 @@ static void asm_parse_directive(TCCState *s1, int global) · 892 unmodified lines | |||
| 893 | if (old_nb_section != s1->nb_sections) | 893 | if (old_nb_section != s1->nb_sections) |
| 894 | cur_text_section->sh_addralign = 1; | 894 | cur_text_section->sh_addralign = 1; |
| 895 | } | 895 | } |
| 896 | /* The section directive supports flags, but they are unsupported. | ||
| 897 | For now, just assume any section contains code. */ | ||
| 898 | cur_text_section->sh_flags |= SHF_EXECINSTR; | ||
| 896 | break; | 899 | break; |
| 897 | case TOK_ASMDIR_previous: | 900 | case TOK_ASMDIR_previous: |
| 898 | { | 901 | { |
| @@ -8303,6 +8303,7 @@ static void gen_function(Sym *sym) · 8302 unmodified lines | |||
| 8303 | cur_scope = root_scope = &f; | 8303 | cur_scope = root_scope = &f; |
| 8304 | nocode_wanted = 0; | 8304 | nocode_wanted = 0; |
| 8305 | 8305 | ||
| 8306 | cur_text_section->sh_flags |= SHF_EXECINSTR; | ||
| 8306 | ind = cur_text_section->data_offset; | 8307 | ind = cur_text_section->data_offset; |
| 8307 | if (sym->a.aligned) { | 8308 | if (sym->a.aligned) { |
| 8308 | size_t newoff = section_add(cur_text_section, 0, | 8309 | size_t newoff = section_add(cur_text_section, 0, |
| @@ -0,0 +1,28 @@ | |||
| 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> | ||
| 7 | |||
| 8 | void *memset(void *dst, int c, int len); | ||
| 9 | |||
| 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" | ||
| 20 | ); | ||
| 21 | |||
| 22 | int main () { | ||
| 23 | char buf[10]; | ||
| 24 | memset(&buf[0], 'A', 9); | ||
| 25 | buf[9] = 0; | ||
| 26 | puts(buf); | ||
| 27 | return 0; | ||
| 28 | } | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | /* Previously in TinyCC, ELF sections defined in attributes would always have | ||
| 2 | the 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 | __attribute__((section(".text.wumbo"))) | ||
| 7 | int wumbo (int arg) { | ||
| 8 | return arg * 2; | ||
| 9 | } | ||
| 10 | |||
| 11 | int main () { | ||
| 12 | return wumbo(2); | ||
| 13 | } | ||