Skip to content

Commit 1401967

Browse files
committed
Fix macos
I fixed macos problem with test case 60. Also tccrun mmap and debug code did not work.
1 parent 1fe3e3b commit 1401967

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tccasm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,11 @@ static void asm_parse_directive(TCCState *s1, int global)
818818

819819
tok1 = tok;
820820
next();
821+
if (tok < TOK_IDENT || tok >= SYM_FIRST_ANOM)
822+
goto nolab;
821823
sym = asm_label_find(tok);
822824
if (!sym) {
825+
nolab:
823826
tcc_error("label not found: %s", get_tok_str(tok1, NULL));
824827
}
825828
/* XXX .size name,label2-label1 */

tccelf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,10 @@ static int tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr)
26152615

26162616
#if TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel
26172617
ehdr.e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
2618+
#elif TARGETOS_OpenBSD
2619+
ehdr.e_ident[EI_OSABI] = ELFOSABI_OPENBSD;
2620+
#elif TARGETOS_NetBSD
2621+
ehdr.e_ident[EI_OSABI] = ELFOSABI_NETBSD;
26182622
#elif defined TCC_TARGET_ARM && defined TCC_ARM_EABI
26192623
ehdr.e_flags = EF_ARM_EABI_VER5;
26202624
ehdr.e_flags |= s1->float_abi == ARM_HARD_FLOAT

tccrun.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ static int rt_mem(TCCState *s1, int size)
121121
ftruncate(fd, size);
122122

123123
ptr = mmap(NULL, size * 2, PROT_READ|PROT_EXEC|(s1->do_debug ? PROT_WRITE : 0), MAP_SHARED, fd, 0);
124+
if (ptr == MAP_FAILED)
125+
/* Some targets do not support PROT_EXEC + PROT_WRITE */
126+
ptr = mmap(NULL, size * 2, PROT_READ|PROT_EXEC, MAP_SHARED, fd, 0);
124127
/* mmap RW memory at fixed distance */
125128
prw = mmap((char*)ptr + size, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 0);
126129
close(fd);
@@ -356,13 +359,23 @@ static int tcc_relocate_ex(TCCState *s1, void *ptr, unsigned ptr_diff)
356359
if (copy == 3)
357360
return 0;
358361

362+
#if defined TCC_TARGET_MACHO
363+
for (k = 0; k < 3; ++k) { /* 0:rx, 1:ro, 3:rw sections */
364+
#else
359365
for (k = 0; k < 4; ++k) { /* 0:rx, 1:ro, 2:ro debug , 3:rw sections */
366+
#endif
360367
n = 0; addr = 0;
361368
for(i = 1; i < s1->nb_sections; i++) {
369+
#if defined TCC_TARGET_MACHO
370+
static const char shf[] = {
371+
SHF_ALLOC|SHF_EXECINSTR, SHF_ALLOC, SHF_ALLOC|SHF_WRITE
372+
};
373+
#else
362374
static const char shf[] = {
363375
SHF_ALLOC|SHF_EXECINSTR, SHF_ALLOC, 0, SHF_ALLOC|SHF_WRITE
364376
};
365377
if (k == 2 && s1->do_debug == 0) continue;
378+
#endif
366379
s = s1->sections[i];
367380
if (shf[k] != (s->sh_flags & (SHF_ALLOC|SHF_WRITE|SHF_EXECINSTR)))
368381
continue;

0 commit comments

Comments
 (0)