Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CONST_HEAP work on macOS #230

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def compile_to_binary(source: str, memory: int, debug: bool) -> str:
with open(os.path.join(dirname, "cli.c"), "r") as f:
c_file.write(f.read())
with tempfile.NamedTemporaryFile(mode="w", suffix=".out", delete=False) as out_file:
print(" ".join([*cc, *cflags, "-o", out_file.name, c_file.name]))
subprocess.run([*cc, *cflags, "-o", out_file.name, c_file.name], check=True)
return out_file.name

Expand Down
16 changes: 14 additions & 2 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,16 @@ struct object* heap_tag(uintptr_t addr) {
#undef __attribute__
#endif

extern char __start_const_heap[];
extern char __stop_const_heap[];
extern char __start_const_heap[]
#ifdef __APPLE__
__asm("section$start$__DATA$const_heap")
#endif
;
extern char __stop_const_heap[]
#ifdef __APPLE__
__asm("section$end$__DATA$const_heap")
#endif
;

bool in_const_heap(struct gc_obj* obj) {
return (uword)obj >= (uword)__start_const_heap &&
Expand Down Expand Up @@ -861,7 +869,11 @@ struct object* println(struct object* obj) {

// Put something in the const heap so that __start_const_heap and
// __stop_const_heap are defined by the linker.
#ifdef __APPLE__
#define CONST_HEAP const __attribute__((section("__DATA,const_heap")))
#else
#define CONST_HEAP const __attribute__((section("const_heap")))
#endif
CONST_HEAP
__attribute__((used)) struct heap_string private_unused_const_heap = {
.HEAD.tag = TAG_STRING, .size = 11, .data = "hello world"};
Loading