From 322c8317d6681409e39c708efc051fe0a4e89836 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 16 Apr 2022 22:24:32 +0200 Subject: [PATCH] Fix non-throwing operator new failure checks being optimized away. --- ext/Makefile | 2 +- games/Makefile | 2 +- kernel/Makefile | 2 +- kernel/op-new.cpp | 6 +++++- libc/Makefile | 2 +- trianglix/Makefile | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/Makefile b/ext/Makefile index 43f1d076..e5c6d431 100644 --- a/ext/Makefile +++ b/ext/Makefile @@ -7,7 +7,7 @@ OPTLEVEL?=$(DEFAULT_OPTLEVEL) CXXFLAGS?=$(OPTLEVEL) CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\" -CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti +CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti -fcheck-new LIBS:=$(LIBS) diff --git a/games/Makefile b/games/Makefile index ab3252de..d522a6c3 100644 --- a/games/Makefile +++ b/games/Makefile @@ -9,7 +9,7 @@ CFLAGS?=$(OPTLEVEL) CXXFLAGS?=$(OPTLEVEL) CFLAGS:=$(CFLAGS) -Wall -Wextra -CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti +CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti -fcheck-new BINARIES:=\ asteroids \ diff --git a/kernel/Makefile b/kernel/Makefile index 0e3daa4d..eb8d1a64 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -13,7 +13,7 @@ CXXFLAGS?=$(OPTLEVEL) CPPFLAGS:=$(CPPFLAGS) -I. -Iinclude -D__is_sortix_kernel CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -ffreestanding -fbuiltin -std=gnu++11 \ - -fno-exceptions -fno-rtti + -fno-exceptions -fno-rtti -fcheck-new ifeq ($(PANIC_SHORT),1) CPPFLAGS:=$(CPPFLAGS) -DPANIC_SHORT diff --git a/kernel/op-new.cpp b/kernel/op-new.cpp index a3d2e7c8..bb15f371 100644 --- a/kernel/op-new.cpp +++ b/kernel/op-new.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2022 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,6 +20,10 @@ #include #include +#ifdef __clang__ +#warning "security: -fcheck-new might not work on clang" +#endif + void* operator new(size_t size) { return malloc(size); diff --git a/libc/Makefile b/libc/Makefile index ed85db51..f6aa3634 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -12,7 +12,7 @@ CPPINCLUDES=-Iinclude CPPFLAGS=-D__is_sortix_libc $(CPPINCLUDES) FLAGS=-Wall -Wextra -ffreestanding $(OPTLEVEL) CFLAGS=-std=gnu11 -Wstrict-prototypes -Werror=implicit-function-declaration -CXXFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti +CXXFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti -fcheck-new ASFLAGS= FREEOBJS=\ diff --git a/trianglix/Makefile b/trianglix/Makefile index 73eca0c1..58afef8d 100644 --- a/trianglix/Makefile +++ b/trianglix/Makefile @@ -7,7 +7,7 @@ include ../build-aux/dirs.mak OPTLEVEL?=-g -O2 CXXFLAGS?=$(OPTLEVEL) -CXXFLAGS:=$(CXXFLAGS) -std=gnu++11 -Wall -Wextra -fno-exceptions -fno-rtti +CXXFLAGS:=$(CXXFLAGS) -std=gnu++11 -Wall -Wextra -fno-exceptions -fno-rtti -fcheck-new BINARY:=trianglix