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

Fix some more UB #31

Merged
merged 4 commits into from
Oct 21, 2022
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
44 changes: 23 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ WERROR ?= 0
RELEASE ?= 0
# Disables/Enables optimizations to make debugging easier
DEBUG ?= 1
ASAN ?= 0

# Can be set to `universal` to build universal binaries on Mac
# On Mac, set this to `universal` to build universal (x86+ARM) binaries
TARGET ?= native
# Set to 1 to build with sanitization enabled
# N.B. cannot be used for `make setup` at the moment due to recomp.cpp not respecting it
ASAN ?= 0

ifeq ($(VERSION),7.1)
IDO_VERSION := IDO71
IDO_VERSION := IDO71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use 4 spaces instead of 2?
Using 2 spaces confuses my vscode and makes it think it should treat tabs as they were 2 spaces instead of 4 which I don't like. This is exactly the reason why I wanted to use tabs instead of spaces here in the first place

# copt currently does not build
IDO_TC := cc acpp as0 as1 cfe ugen ujoin uld umerge uopt usplit
IDO_TC := cc acpp as0 as1 cfe ugen ujoin uld umerge uopt usplit
else ifeq ($(VERSION),5.3)
IDO_VERSION := IDO53
IDO_TC := cc acpp as0 as1 cfe copt ugen ujoin uld umerge uopt usplit
IDO_VERSION := IDO53
IDO_TC := cc acpp as0 as1 cfe copt ugen ujoin uld umerge uopt usplit
else
$(error Unknown or unsupported IDO version - $(VERSION))
$(error Unknown or unsupported IDO version - $(VERSION))
endif


Expand All @@ -42,15 +43,15 @@ UNAME_P := $(shell uname -p)

MAKE := make
ifeq ($(OS),Windows_NT)
DETECTED_OS := windows
DETECTED_OS := windows
else ifeq ($(UNAME_S),Linux)
DETECTED_OS := linux
DETECTED_OS := linux
else ifeq ($(UNAME_S),Darwin)
DETECTED_OS := macos
MAKE := gmake
CPPFLAGS += -xc++
DETECTED_OS := macos
MAKE := gmake
CPPFLAGS += -xc++
else
$(error Unsupported host OS for Makefile)
$(error Unsupported host OS for Makefile)
endif

RABBITIZER := tools/rabbitizer
Expand All @@ -69,26 +70,27 @@ LDFLAGS ?= -lm
RECOMP_FLAGS ?=

ifneq ($(WERROR),0)
WARNINGS += -Werror
WARNINGS += -Werror
endif

ifeq ($(RELEASE),0)
STRIP := @:
STRIP := @:
endif

ifeq ($(DEBUG),0)
OPTFLAGS ?= -Os
OPTFLAGS ?= -Os
else
OPTFLAGS ?= -O0 -g3
OPTFLAGS ?= -O0 -g3
endif

ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fno-sanitize-recover=all
CXXFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fno-sanitize-recover=all
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fno-sanitize-recover=all
CXXFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined -fno-sanitize-recover=all
endif


ifeq ($(DETECTED_OS),windows)
CXXFLAGS += -static
CXXFLAGS += -static
endif

# -- Build Directories
Expand Down
8 changes: 4 additions & 4 deletions libc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,7 @@ double wrapper_ldexp(double d, int i) {
return ldexp(d, i);
}

int64_t wrapper___ll_mul(int64_t a0, int64_t a1) {
uint64_t wrapper___ll_mul(uint64_t a0, uint64_t a1) {
return a0 * a1;
}

Expand All @@ -2172,12 +2172,12 @@ int64_t wrapper___ll_rem(uint64_t a0, int64_t a1) {
return a0 % a1;
}

int64_t wrapper___ll_lshift(int64_t a0, uint64_t shift) {
return a0 << (shift & 0x3f);
uint64_t wrapper___ll_lshift(uint64_t a0, uint64_t shift) {
return a0 << (shift & 0x3F);
}

int64_t wrapper___ll_rshift(int64_t a0, uint64_t shift) {
return a0 >> (shift & 0x3f);
return a0 >> (shift & 0x3F);
}

uint64_t wrapper___ull_div(uint64_t a0, uint64_t a1) {
Expand Down
4 changes: 2 additions & 2 deletions libc_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ int wrapper_time(uint8_t *mem, uint32_t tloc_addr);
void wrapper_bzero(uint8_t *mem, uint32_t str_addr, uint32_t n);
int wrapper_fp_class_d(double d);
double wrapper_ldexp(double d, int i);
int64_t wrapper___ll_mul(int64_t a0, int64_t a1);
uint64_t wrapper___ll_mul(uint64_t a0, uint64_t a1);
int64_t wrapper___ll_div(int64_t a0, int64_t a1);
int64_t wrapper___ll_rem(uint64_t a0, int64_t a1);
int64_t wrapper___ll_lshift(int64_t a0, uint64_t shift);
uint64_t wrapper___ll_lshift(uint64_t a0, uint64_t shift);
int64_t wrapper___ll_rshift(int64_t a0, uint64_t shift);
uint64_t wrapper___ull_div(uint64_t a0, uint64_t a1);
uint64_t wrapper___ull_rem(uint64_t a0, uint64_t a1);
Expand Down