Skip to content

Commit 95f7e80

Browse files
authored
flambda-backend: Provide a no-naked-pointers runtime and use it for the compiler (#1224)
1 parent ba77581 commit 95f7e80

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

runtime/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ ifeq "$(SUPPORTS_SHARED_LIBRARIES)" "true"
7676
BYTECODE_STATIC_LIBRARIES += libcamlrun_pic.$(A)
7777
BYTECODE_SHARED_LIBRARIES += libcamlrun_shared.$(SO)
7878
NATIVE_STATIC_LIBRARIES += libasmrun_pic.$(A)
79+
NATIVE_STATIC_LIBRARIES += libasmrunnnp.$(A)
7980
NATIVE_SHARED_LIBRARIES += libasmrun_shared.$(SO)
8081
endif
8182
endif
@@ -106,6 +107,8 @@ libasmruni_OBJECTS := $(NATIVE_C_SOURCES:.c=.ni.$(O)) $(ASM_OBJECTS)
106107
libasmrunpic_OBJECTS := $(NATIVE_C_SOURCES:.c=.npic.$(O)) \
107108
$(ASM_OBJECTS:.$(O)=_libasmrunpic.$(O))
108109

110+
libasmrunnnp_OBJECTS := $(NATIVE_C_SOURCES:.c=.nnp.$(O)) $(ASM_OBJECTS)
111+
109112
# General (non target-specific) assembler and compiler flags
110113

111114
ifneq "$(CCOMPTYPE)" "msvc"
@@ -310,6 +313,9 @@ libasmruni.$(A): $(libasmruni_OBJECTS)
310313
libasmrun_pic.$(A): $(libasmrunpic_OBJECTS)
311314
$(call MKLIB,$@, $^)
312315

316+
libasmrunnnp.$(A): $(libasmrunnnp_OBJECTS)
317+
$(call MKLIB,$@, $^)
318+
313319
libasmrun_shared.$(SO): $(libasmrunpic_OBJECTS)
314320
$(MKDLL) -o $@ $^ $(NATIVECCLIBS)
315321

@@ -336,6 +342,9 @@ libasmrun_shared.$(SO): $(libasmrunpic_OBJECTS)
336342
%.npic.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
337343
%.npic.$(D): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
338344

345+
%.nnp.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) -DNO_NAKED_POINTERS
346+
%.nnp.$(D): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) -DNO_NAKED_POINTERS
347+
339348
# The major GC performs better with this flag on Intel processors
340349
# This is a workaround for an Intel CPU bug:
341350
# https://www.intel.co.uk/content/www/uk/en/support/articles/000055650/processors.html
@@ -369,7 +378,7 @@ endef
369378

370379
object_types := % %.b %.bd %.bi %.bpic
371380
ifneq "$(NATIVE_COMPILER)" "false"
372-
object_types += %.n %.nd %.ni %.np %.npic
381+
object_types += %.n %.nnp %.nd %.ni %.np %.npic
373382
endif
374383

375384
$(foreach object_type, $(object_types), \
@@ -414,6 +423,7 @@ i386nt.obj: i386nt.asm domain_state32.inc
414423
DEP_FILES := $(addsuffix .b, $(basename $(BYTECODE_C_SOURCES) instrtrace))
415424
ifneq "$(NATIVE_COMPILER)" "false"
416425
DEP_FILES += $(addsuffix .n, $(basename $(NATIVE_C_SOURCES)))
426+
DEP_FILES += $(addsuffix .nnp, $(basename $(NATIVE_C_SOURCES)))
417427
endif
418428
DEP_FILES += $(addsuffix d, $(DEP_FILES)) \
419429
$(addsuffix i, $(DEP_FILES)) \

runtime/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(action (with-stdout-to %{targets} (run %{dep:gen_primitives.sh}))))
2828

2929
(rule
30-
(targets libasmrun.a libasmrund.a libasmruni.a libasmrun_pic.a
30+
(targets libasmrun.a libasmrund.a libasmruni.a libasmrun_pic.a libasmrunnnp.a
3131
libasmrun_shared.so libcamlrun.a libcamlrund.a libcamlruni.a libcamlrun_pic.a
3232
libcamlrun_shared.so ocamlrun ocamlrund ocamlruni ld.conf
3333
sak)
@@ -77,6 +77,7 @@
7777
libasmrund.a
7878
libasmruni.a
7979
libasmrun_pic.a
80+
libasmrunnnp.a
8081
libasmrun_shared.so
8182
)
8283
(section lib)

runtime/memory.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ static struct page_table caml_page_table;
9090

9191
int caml_page_table_lookup(void * addr)
9292
{
93+
#ifdef NO_NAKED_POINTERS
94+
/* This case should only be hit if C stubs compiled without
95+
NO_NAKED_POINTERS are linked into an executable using
96+
"-runtime-variant nnp". The return value here should cause the
97+
macros in address_class.h to give the same results as when they
98+
are compiled with NO_NAKED_POINTERS defined. */
99+
100+
caml_local_arenas* local_arenas = Caml_state->local_arenas;
101+
102+
if (Is_young(addr))
103+
return In_heap | In_young;
104+
105+
if (local_arenas != NULL) {
106+
int arena;
107+
for (arena = 0; arena < local_arenas->count; arena++) {
108+
char* start = local_arenas->arenas[arena].base;
109+
char* end = start + local_arenas->arenas[arena].length;
110+
if ((char*) addr >= start && (char*) addr < end)
111+
return In_heap | In_local;
112+
}
113+
}
114+
115+
return In_heap;
116+
#else
93117
uintnat h, e;
94118

95119
h = Hash(Page(addr));
@@ -102,6 +126,7 @@ int caml_page_table_lookup(void * addr)
102126
e = caml_page_table.entries[h];
103127
if (Page_entry_matches(e, (uintnat)addr)) return e & 0xFF;
104128
}
129+
#endif
105130
}
106131

107132
int caml_page_table_initialize(mlsize_t bytesize)

0 commit comments

Comments
 (0)