-
Notifications
You must be signed in to change notification settings - Fork 144
Support Arm dynamic linking #244
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
base: master
Are you sure you want to change the base?
Changes from all commits
43066fb
08b039f
209520e
f359556
afb1233
7934ef3
8888be7
bcb515f
01775f6
9c3e8f7
e23d35a
9311135
071636b
7da4554
cd9ceba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,12 +43,26 @@ HOST_ARCH = $(shell arch 2>/dev/null) | |||||||||
| SRCDIR := $(shell find src -type d) | ||||||||||
| LIBDIR := $(shell find lib -type d) | ||||||||||
|
|
||||||||||
| BUILTIN_LIBC_SOURCE ?= c.c | ||||||||||
| BUILTIN_LIBC_HEADER := c.h | ||||||||||
| STAGE0_FLAGS ?= --dump-ir | ||||||||||
| STAGE1_FLAGS ?= | ||||||||||
| ifeq ($(DYNLINK),1) | ||||||||||
| ifeq ($(ARCH),riscv) | ||||||||||
| # TODO: implement dynamic linking for RISC-V. | ||||||||||
| $(error "Dynamic linking mode is not implemented for RISC-V") | ||||||||||
| endif | ||||||||||
| STAGE0_FLAGS += --dynlink | ||||||||||
| STAGE1_FLAGS += --dynlink | ||||||||||
| endif | ||||||||||
|
|
||||||||||
| SRCS := $(wildcard $(patsubst %,%/main.c, $(SRCDIR))) | ||||||||||
| OBJS := $(SRCS:%.c=$(OUT)/%.o) | ||||||||||
| deps := $(OBJS:%.o=%.o.d) | ||||||||||
| TESTS := $(wildcard tests/*.c) | ||||||||||
| TESTBINS := $(TESTS:%.c=$(OUT)/%.elf) | ||||||||||
| SNAPSHOTS := $(foreach SNAPSHOT_ARCH,$(ARCHS), $(patsubst tests/%.c, tests/snapshots/%-$(SNAPSHOT_ARCH).json, $(TESTS))) | ||||||||||
| SNAPSHOTS = $(foreach SNAPSHOT_ARCH,$(ARCHS), $(patsubst tests/%.c, tests/snapshots/%-$(SNAPSHOT_ARCH)-static.json, $(TESTS))) | ||||||||||
| SNAPSHOTS += $(patsubst tests/%.c, tests/snapshots/%-arm-dynamic.json, $(TESTS)) | ||||||||||
|
|
||||||||||
| all: config bootstrap | ||||||||||
|
|
||||||||||
|
|
@@ -72,44 +86,46 @@ config: | |||||||||
|
|
||||||||||
| $(OUT)/tests/%.elf: tests/%.c $(OUT)/$(STAGE0) | ||||||||||
| $(VECHO) " SHECC\t$@\n" | ||||||||||
| $(Q)$(OUT)/$(STAGE0) --dump-ir -o $@ $< > $(basename $@).log ; \ | ||||||||||
| $(Q)$(OUT)/$(STAGE0) $(STAGE0_FLAGS) -o $@ $< > $(basename $@).log ; \ | ||||||||||
| chmod +x $@ ; $(PRINTF) "Running $@ ...\n" | ||||||||||
| $(Q)$(TARGET_EXEC) $@ && $(call pass) | ||||||||||
|
|
||||||||||
| check: check-stage0 check-stage2 | ||||||||||
|
|
||||||||||
| check-stage0: $(OUT)/$(STAGE0) $(TESTBINS) tests/driver.sh | ||||||||||
| $(VECHO) " TEST STAGE 0\n" | ||||||||||
| tests/driver.sh 0 | ||||||||||
| tests/driver.sh 0 $(DYNLINK) | ||||||||||
|
|
||||||||||
| check-stage2: $(OUT)/$(STAGE2) $(TESTBINS) tests/driver.sh | ||||||||||
| $(VECHO) " TEST STAGE 2\n" | ||||||||||
| tests/driver.sh 2 | ||||||||||
| tests/driver.sh 2 $(DYNLINK) | ||||||||||
|
|
||||||||||
| check-sanitizer: $(OUT)/$(STAGE0)-sanitizer tests/driver.sh | ||||||||||
| $(VECHO) " TEST STAGE 0 (with sanitizers)\n" | ||||||||||
| $(Q)cp $(OUT)/$(STAGE0)-sanitizer $(OUT)/shecc | ||||||||||
| tests/driver.sh 0 | ||||||||||
| tests/driver.sh 0 $(DYNLINK) | ||||||||||
| $(Q)rm $(OUT)/shecc | ||||||||||
|
|
||||||||||
| check-snapshots: $(OUT)/$(STAGE0) $(SNAPSHOTS) tests/check-snapshots.sh | ||||||||||
| $(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;) | ||||||||||
| $(VECHO) "Switching backend back to %s\n" $(ARCH) | ||||||||||
| $(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent | ||||||||||
| $(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config check-snapshot ARCH=$(SNAPSHOT_ARCH) DYNLINK=0 --silent;) | ||||||||||
| $(Q)$(MAKE) distclean config check-snapshot ARCH=arm DYNLINK=1 --silent | ||||||||||
| $(VECHO) "Switching backend back to %s (DYNLINK=0)\n" arm | ||||||||||
| $(Q)$(MAKE) distclean config ARCH=arm --silent | ||||||||||
|
|
||||||||||
| check-snapshot: $(OUT)/$(STAGE0) tests/check-snapshots.sh | ||||||||||
| $(VECHO) "Checking snapshot for %s\n" $(ARCH) | ||||||||||
| tests/check-snapshots.sh $(ARCH) | ||||||||||
| $(VECHO) "Checking snapshot for %s (%s mode)\n" $(ARCH) $(DYNLINK) | ||||||||||
| tests/check-snapshots.sh $(ARCH) $(DYNLINK) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make check-snapshot now fails unless DYNLINK is set because $(DYNLINK) expands to empty and the script expects a second argument. Please default this call to static mode when DYNLINK is unset. Prompt for AI agents
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt for AI agents
Suggested change
|
||||||||||
| $(VECHO) " OK\n" | ||||||||||
|
|
||||||||||
| update-snapshots: tests/update-snapshots.sh | ||||||||||
| $(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) --silent;) | ||||||||||
| $(VECHO) "Switching backend back to %s\n" $(ARCH) | ||||||||||
| $(Q)$(MAKE) distclean config ARCH=$(ARCH) --silent | ||||||||||
| $(Q)$(foreach SNAPSHOT_ARCH, $(ARCHS), $(MAKE) distclean config update-snapshot ARCH=$(SNAPSHOT_ARCH) DYNLINK=0 --silent;) | ||||||||||
| $(Q)$(MAKE) distclean config update-snapshot ARCH=arm DYNLINK=1 --silent | ||||||||||
| $(VECHO) "Switching backend back to %s (DYNLINK=0)\n" arm | ||||||||||
| $(Q)$(MAKE) distclean config ARCH=arm --silent | ||||||||||
|
|
||||||||||
| update-snapshot: $(OUT)/$(STAGE0) tests/update-snapshots.sh | ||||||||||
| $(VECHO) "Updating snapshot for %s\n" $(ARCH) | ||||||||||
| tests/update-snapshots.sh $(ARCH) | ||||||||||
| $(VECHO) "Updating snapshot for %s (DYNLINK=%s)\n" $(ARCH) $(DYNLINK) | ||||||||||
| tests/update-snapshots.sh $(ARCH) $(DYNLINK) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make update-snapshot now aborts unless DYNLINK is defined because the helper script insists on two arguments. Please provide a default value (e.g., static mode) when DYNLINK is unset. Prompt for AI agents
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt for AI agents
Suggested change
|
||||||||||
| $(VECHO) " OK\n" | ||||||||||
|
|
||||||||||
| $(OUT)/%.o: %.c | ||||||||||
|
|
@@ -122,11 +138,12 @@ $(OUT)/norm-lf: tools/norm-lf.c | |||||||||
| $(VECHO) " CC+LD\t$@\n" | ||||||||||
| $(Q)$(CC) $(CFLAGS) -o $@ $^ | ||||||||||
|
|
||||||||||
| $(OUT)/libc.inc: $(OUT)/inliner $(OUT)/norm-lf $(LIBDIR)/c.c | ||||||||||
| $(OUT)/libc.inc: $(OUT)/inliner $(OUT)/norm-lf $(LIBDIR)/$(BUILTIN_LIBC_SOURCE) $(LIBDIR)/$(BUILTIN_LIBC_HEADER) | ||||||||||
| $(VECHO) " GEN\t$@\n" | ||||||||||
| $(Q)$(OUT)/norm-lf $(LIBDIR)/c.c $(OUT)/c.normalized.c | ||||||||||
| $(Q)$(OUT)/inliner $(OUT)/c.normalized.c $@ | ||||||||||
| $(Q)$(RM) $(OUT)/c.normalized.c | ||||||||||
| $(Q)$(OUT)/norm-lf $(LIBDIR)/$(BUILTIN_LIBC_SOURCE) $(OUT)/c.normalized.c | ||||||||||
| $(Q)$(OUT)/norm-lf $(LIBDIR)/$(BUILTIN_LIBC_HEADER) $(OUT)/c.normalized.h | ||||||||||
| $(Q)$(OUT)/inliner $(OUT)/c.normalized.c $(OUT)/c.normalized.h $@ | ||||||||||
| $(Q)$(RM) $(OUT)/c.normalized.c $(OUT)/c.normalized.h | ||||||||||
|
|
||||||||||
| $(OUT)/inliner: tools/inliner.c | ||||||||||
| $(VECHO) " CC+LD\t$@\n" | ||||||||||
|
|
@@ -143,12 +160,12 @@ $(OUT)/$(STAGE0)-sanitizer: $(OUT)/libc.inc $(OBJS) | |||||||||
| $(OUT)/$(STAGE1): $(OUT)/$(STAGE0) | ||||||||||
| $(Q)$(STAGE1_CHECK_CMD) | ||||||||||
| $(VECHO) " SHECC\t$@\n" | ||||||||||
| $(Q)$(OUT)/$(STAGE0) --dump-ir -o $@ $(SRCDIR)/main.c > $(OUT)/shecc-stage1.log | ||||||||||
| $(Q)$(OUT)/$(STAGE0) $(STAGE0_FLAGS) -o $@ $(SRCDIR)/main.c > $(OUT)/shecc-stage1.log | ||||||||||
| $(Q)chmod a+x $@ | ||||||||||
|
|
||||||||||
| $(OUT)/$(STAGE2): $(OUT)/$(STAGE1) | ||||||||||
| $(VECHO) " SHECC\t$@\n" | ||||||||||
| $(Q)$(TARGET_EXEC) $(OUT)/$(STAGE1) -o $@ $(SRCDIR)/main.c | ||||||||||
| $(Q)$(TARGET_EXEC) $(OUT)/$(STAGE1) $(STAGE1_FLAGS) -o $@ $(SRCDIR)/main.c | ||||||||||
|
|
||||||||||
| bootstrap: $(OUT)/$(STAGE2) | ||||||||||
| $(Q)chmod 775 $(OUT)/$(STAGE2) | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.