Unified · Split
| @@ -825,7 +825,11 @@ static void tcc_add_runtime(TCCState *s1) · 824 unmodified lines | ||
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /* name of ELF interpreter */ |
| 828 | +#ifdef __FreeBSD__ | |
| 829 | +static char elf_interp[] = "/usr/libexec/ld-elf.so.1"; | |
| 830 | +#else | |
| 828 | 831 | static char elf_interp[] = "/lib/ld-linux.so.2"; |
| 832 | +#endif | |
| 829 | 833 | |
| 830 | 834 | #define ELF_START_ADDR 0x08048000 |
| 831 | 835 | #define ELF_PAGE_SIZE 0x1000 |
| @@ -1165,6 +1169,10 @@ int tcc_output_file(TCCState *s1, const char *filename) · 333 unmodified lines | ||
| 1165 | 1169 | ph->p_filesz = file_offset - ph->p_offset; |
| 1166 | 1170 | ph->p_memsz = addr - ph->p_vaddr; |
| 1167 | 1171 | ph++; |
| 1172 | + /* if in the middle of a page, we duplicate the page in | |
| 1173 | + memory so that one copy is RX and the other is RW */ | |
| 1174 | + if ((addr & (ELF_PAGE_SIZE - 1)) != 0) | |
| 1175 | + addr += ELF_PAGE_SIZE; | |
| 1168 | 1176 | } |
| 1169 | 1177 | |
| 1170 | 1178 | /* if interpreter, then add corresponing program header */ |
| @@ -1324,6 +1332,9 @@ int tcc_output_file(TCCState *s1, const char *filename) · 153 unmodified lines | ||
| 1324 | 1332 | ehdr.e_ident[4] = ELFCLASS32; |
| 1325 | 1333 | ehdr.e_ident[5] = ELFDATA2LSB; |
| 1326 | 1334 | ehdr.e_ident[6] = EV_CURRENT; |
| 1335 | +#ifdef __FreeBSD__ | |
| 1336 | + ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD; | |
| 1337 | +#endif | |
| 1327 | 1338 | switch(file_type) { |
| 1328 | 1339 | default: |
| 1329 | 1340 | case TCC_OUTPUT_EXE: |