Updating build to hopefully allow OSX builds.
dlsym opcode modified so that 0 for library is converted to RTLD_DEFAULT as the two don't match on Darwin. Made errno an opcode, as previous method depended on Linux internals. [1] https://opensource.apple.com/source/xnu/xnu-201/osfmk/libsa/errno.h.auto.html [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html Placed errno in internals and then alias inside posix vocabulary, as it seemed a waste to have another builtin stub for one symbol. Arguably maybe dlsym should be that way too, but leaving for now. Added OS make variable to conditionally set flags. Set stripping / minimization options based on it. Based off of https://github.com/flagxor/ueforth/pull/3 Thanks Ulrich!
This commit is contained in:
32
Makefile
32
Makefile
@ -28,6 +28,8 @@ ESP32 = $(OUT)/esp32
|
||||
ESP32_SIM = $(OUT)/esp32-sim
|
||||
DEPLOY = $(OUT)/deploy
|
||||
|
||||
OS = $(shell uname -s)
|
||||
|
||||
CFLAGS_COMMON = -O2 -I ./ -I $(OUT)
|
||||
|
||||
CFLAGS_MINIMIZE = \
|
||||
@ -37,7 +39,7 @@ CFLAGS_MINIMIZE = \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fomit-frame-pointer \
|
||||
-fno-ident -Wl,--build-id=none \
|
||||
-fno-ident \
|
||||
-ffunction-sections -fdata-sections \
|
||||
-fmerge-all-constants
|
||||
CFLAGS = $(CFLAGS_COMMON) \
|
||||
@ -47,13 +49,27 @@ CFLAGS = $(CFLAGS_COMMON) \
|
||||
-Werror \
|
||||
-no-pie \
|
||||
-Wl,--gc-sections
|
||||
STRIP_ARGS = -S \
|
||||
--strip-unneeded \
|
||||
--remove-section=.note.gnu.gold-version \
|
||||
--remove-section=.comment \
|
||||
--remove-section=.note \
|
||||
--remove-section=.note.gnu.build-id \
|
||||
--remove-section=.note.ABI-tag
|
||||
ifeq ($(OS),Darwin)
|
||||
CFLAGS += -Wl,-dead_strip -D_GNU_SOURCE
|
||||
endif
|
||||
ifeq ($(OS),Linux)
|
||||
CFLAGS_MINIMIZE += -Wl,--build-id=none
|
||||
CFLAGS += -s -Wl,--gc-sections -no-pie -Wl,--build-id=none
|
||||
endif
|
||||
|
||||
STRIP_ARGS = -S
|
||||
ifeq ($(OS),Darwin)
|
||||
STRIP_ARGS += -x
|
||||
endif
|
||||
ifeq ($(OS),Linux)
|
||||
STRIP_ARGS += --strip-unneeded \
|
||||
--remove-section=.note.gnu.gold-version \
|
||||
--remove-section=.comment \
|
||||
--remove-section=.note \
|
||||
--remove-section=.note.gnu.build-id \
|
||||
--remove-section=.note.ABI-tag
|
||||
endif
|
||||
|
||||
LIBS=-ldl
|
||||
|
||||
WIN_CFLAGS = $(CFLAGS_COMMON) \
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common/tier0_opcodes.h"
|
||||
@ -24,8 +25,11 @@
|
||||
#define HEAP_SIZE (10 * 1024 * 1024)
|
||||
#define STACK_CELLS (8 * 1024)
|
||||
|
||||
// NOTE: errno implemented as opcode to avoid a Linux platform dependency.
|
||||
|
||||
#define PLATFORM_OPCODE_LIST \
|
||||
Y(DLSYM, tos = (cell_t) dlsym(a1, c0); --sp) \
|
||||
Y(DLSYM, tos = (cell_t) dlsym(a1 ? a1 : RTLD_DEFAULT, c0); NIP) \
|
||||
XV(internals, "errno", ERRNO_INTERNAL, DUP; tos = (cell_t) errno) \
|
||||
CALLING_OPCODE_LIST \
|
||||
FLOATING_POINT_LIST
|
||||
|
||||
|
||||
@ -69,8 +69,9 @@ z" readdir" 1 sysfunc readdir
|
||||
: .d_name ( a -- z ) 19 + ;
|
||||
|
||||
( Errno )
|
||||
z" __errno_location" 0 sysfunc __errno_location
|
||||
: errno ( -- n ) __errno_location sl@ ;
|
||||
also internals
|
||||
: errno ( -- n ) errno ;
|
||||
previous
|
||||
|
||||
( Default Pipes )
|
||||
0 constant stdin
|
||||
|
||||
Reference in New Issue
Block a user