diff options
| author | Albert Ou <albert@sifive.com> | 2016-12-13 15:05:19 -0800 |
|---|---|---|
| committer | Albert Ou <albert@sifive.com> | 2016-12-14 12:23:40 -0800 |
| commit | 3dbaad0a1f27b96462541e1189efe37ffa913e9a (patch) | |
| tree | f50f770a39bc5d9fd9296862b4806c5dd7d0eed6 /bsp/libwrap/libwrap.mk | |
| parent | 82d5cab92318ca82f6fb95921cd70e4aefa28cd9 (diff) | |
Refactor libc stubs into libwrap
The --wrap feature of GNU ld supports a cleaner framework for linking in
alternative implementations of libc functions without cpp hacks.
Place wrappers in separate object files to reduce static code size.
Diffstat (limited to 'bsp/libwrap/libwrap.mk')
| -rw-r--r-- | bsp/libwrap/libwrap.mk | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/bsp/libwrap/libwrap.mk b/bsp/libwrap/libwrap.mk new file mode 100644 index 0000000..313ed00 --- /dev/null +++ b/bsp/libwrap/libwrap.mk @@ -0,0 +1,54 @@ +# See LICENSE for license details. + +ifndef _SIFIVE_MK_LIBWRAP +_SIFIVE_MK_LIBWRAP := # defined + +LIBWRAP_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +LIBWRAP_DIR := $(LIBWRAP_DIR:/=) + +LIBWRAP_SRCS := \ + stdlib/malloc.c \ + sys/open.c \ + sys/lseek.c \ + sys/read.c \ + sys/write.c \ + sys/fstat.c \ + sys/stat.c \ + sys/close.c \ + sys/link.c \ + sys/unlink.c \ + sys/execve.c \ + sys/fork.c \ + sys/getpid.c \ + sys/kill.c \ + sys/wait.c \ + sys/isatty.c \ + sys/times.c \ + sys/sbrk.c \ + sys/_exit.c \ + misc/write_hex.c + +LIBWRAP_SRCS := $(foreach f,$(LIBWRAP_SRCS),$(LIBWRAP_DIR)/$(f)) +LIBWRAP_OBJS := $(LIBWRAP_SRCS:.c=.o) + +LIBWRAP_SYMS := malloc free \ + open lseek read write fstat stat close link unlink \ + execve fork getpid kill wait \ + isatty times sbrk _exit + +LIBWRAP := libwrap.a + +LINK_DEPS += $(LIBWRAP) + +LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=$(s)) +LDFLAGS += -L. -Wl,--start-group -lwrap -lc -Wl,--end-group + +CLEAN_OBJS += $(LIBWRAP_OBJS) + +$(LIBWRAP_OBJS): %.o: %.c $(HEADERS) + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +$(LIBWRAP): $(LIBWRAP_OBJS) + $(AR) rcs $@ $^ + +endif # _SIFIVE_MK_LIBWRAP |
