]> Untitled Git - axy/ft/c-cera.git/commitdiff
Updated makefile a bunch
authorAxy <gilliardmarthey.axel@gmail.com>
Fri, 15 May 2026 11:10:03 +0000 (13:10 +0200)
committerAxy <gilliardmarthey.axel@gmail.com>
Fri, 15 May 2026 11:10:03 +0000 (13:10 +0200)
12 files changed:
.deps
Makefile
conf.mk [new file with mode: 0644]
src/arc.c
src/arc.h
src/atomic.h [new file with mode: 0644]
src/ccera.h
src/defer.c
src/panic.c
src/stacktrack.c
src/value_types.h
test.c

diff --git a/.deps b/.deps
index 47f68db7a76631b11a9f29daaddaed5c1ce527c4..3fe262b5bf0e73908675886f661d1a9a1bbaaa1d 100644 (file)
--- a/.deps
+++ b/.deps
@@ -1,11 +1,11 @@
 ${BUILDDIR}/arc.o: src/arc.c src/arc.h src/memutils.h src/panic.h src/jmp.h \
-  src/arith.h
+  src/arith.h src/atomic.h
 ${BUILDDIR}/defer.o: src/defer.c src/defer.h src/framealloc.h src/align.h \
   src/stacktrack.h src/memutils.h src/panic.h src/jmp.h
 ${BUILDDIR}/eval.o: src/eval.c src/ccera.h src/jmp.h src/defer.h src/framealloc.h \
   src/align.h src/stacktrack.h src/memutils.h src/panic.h src/value.h \
   src/value_get.h src/value_types.h src/value_new.h src/arith.h \
-  src/arc.h
+  src/arc.h src/atomic.h
 ${BUILDDIR}/framealloc.o: src/framealloc.c src/framealloc.h src/align.h \
   src/stacktrack.h
 ${BUILDDIR}/panic.o: src/panic.c src/panic.h src/jmp.h src/defer.h src/framealloc.h \
index f2350d76e87060dd0f57bd3d1d30ea048b547423..bf29c678a5ef062131fe500c813076109c4b5097 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,12 @@ NAME=ccera.a
 
 SRCS=src/arc.c src/defer.c src/eval.c src/framealloc.c src/panic.c src/stacktrack.c src/value_lifetime.c src/value_list.c src/value_move.c src/value_new.c
 
-HEADERS=src/align.h src/arc.h src/arith.h src/ccera.h src/defer.h src/framealloc.h src/jmp.h src/memutils.h src/panic.h src/stacktrack.h src/value_get.h src/value.h src/value_new.h src/value_types.h
+HEADERS=src/align.h src/arc.h src/arith.h src/atomic.h src/ccera.h src/defer.h src/framealloc.h src/jmp.h src/memutils.h src/panic.h src/stacktrack.h src/value_get.h src/value.h src/value_new.h src/value_types.h
+
+CC = cc
+
+CONFFILE ?= conf.mk
+include ${CONFFILE}
 
 BUILDDIR=.build
 
@@ -12,27 +17,72 @@ DEPSFILE=.deps
 
 OBJS=${SRCS:src/%.c=${BUILDDIR}/%.o}
 
-CFLAGS=-Wall -Wextra -Werror -pthread -std=gnu17
-# IMPORTANT: We use this to properly keep track of stack frames at a source level
-CFLAGS += -finstrument-functions
+CFLAGS ?=
+
+CFLAGS += -Wall -Wextra -Werror -pthread -finstrument-functions
+
+CFLAGS += -std=gnu99
+
 CFLAGS += -g
-CFLAGS += -O3
-#CFLAGS += -flto -ffat-lto-objects
 CFLAGS += -fdiagnostics-color
 
-#CC=clang
-#CC=gcc
-CC=cc
+CFLAGS += -O3
 
-AR=gcc-ar
+LTO ?= 0
+
+UBSAN ?= 0
+ifeq (${UBSAN}, 1)
+CFLAGS += -fsanitize=undefined
+endif
+
+TSAN ?= 0
+ifeq (${TSAN}, 1)
+CFLAGS += -fsanitize=thread
+# Tsan incompat with lto
+ifeq (${LTO}, 1)
+$(info Disabling LTO because TSAN is enabled)
+endif
+LTO=0
+endif
+
+ASAN ?= 0
+ifeq (${ASAN}, 1)
+CFLAGS += -fsanitize=address
+# Tsan incompat with lto
+ifeq (${LTO}, 1)
+$(info Disabling LTO because ASAN is enabled)
+endif
+LTO=0
+endif
+
+ifeq (${CC}, gcc)
+ifeq (${LTO}, 1)
+$(info Disabling LTO because gcc has SSA corruption bug)
+CFLAGS += -flto -ffat-lto-objects
+endif
+endif
+
+ifeq (${LTO}, 1)
+CFLAGS += -flto -ffat-lto-objects
+endif
+
+AR=ar
+
+MAKE_CMD=CONFFILE=${CONFFILE} make
 
 MAKEFLAGS += --no-print-directory
 
 all: ${NAME}
 
+${CONFFILE}:
+       touch $@
+
+${DEPSFILE}:
+       touch $@
+
 include ${DEPSFILE}
 
-${BUILDDIR}/%.o: src/%.c ${THIS} ${DEPSFILE} | ${BUILDDIR}
+${BUILDDIR}/%.o: src/%.c ${THIS} ${DEPSFILE} ${CONFFILE} | ${BUILDDIR}
        ${CC} ${CFLAGS} -c -o $@ $<
 
 ${BUILDDIR}:
@@ -82,26 +132,18 @@ norm: .norm
        @test ! -e .norm_fail
 
 watch-step:
-       make remakefile
-       make redeps
-       make norm
-       make
+       ${MAKE_CMD} remakefile
+       ${MAKE_CMD} redeps
+       ${MAKE_CMD} norm
+       ${MAKE_CMD} all
 
 watch:
-       watch -c -n 1 make watch-step
+       watch -c -n 1 ${MAKE_CMD} watch-step
 
-norm-watch:
-       watch -c -n 1 make norm
-
-build-watch:
-       watch -c -n 1 make
-
-a.out: test.c ${NAME} ${THIS} 
-       ${CC} ${CFLAGS} test.c ccera.a
+a.out: test.c ${NAME}
+       ${CC} ${CFLAGS} $^
 
 test: a.out
-       valgrind ./a.out
+       ./a.out
 
 .PHONY: all clean fclean re remakefile redeps norm watch-step watch test
-
-${BUILDDIR}/arc.o: src/arc.c src/arc.h
diff --git a/conf.mk b/conf.mk
new file mode 100644 (file)
index 0000000..75d7d55
--- /dev/null
+++ b/conf.mk
@@ -0,0 +1,5 @@
+#LTO=1
+CC=clang
+#UBSAN=1
+TSAN=1
+#ASAN=1
index 76bbaed8e716fc54633ca765070b6826362f11ad..fa34fd18feeaaee95a84df7b36765c274cb62f0c 100644 (file)
--- a/src/arc.c
+++ b/src/arc.c
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/04/29 16:40:27 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/13 16:42:04 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:22:29 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -15,6 +15,7 @@
 #include "panic.h"
 #include "memutils.h"
 #include "arith.h"
+#include "atomic.h"
 
 t_arc  arc_new(size_t size)
 {
@@ -40,7 +41,7 @@ void  arc_drop(t_arc arc, t_drop destructor)
 {
        if (__atomic_sub_fetch(((size_t *)arc) - 1, 1, __ATOMIC_RELEASE) != 0)
                return ;
-       __atomic_thread_fence(__ATOMIC_ACQUIRE);
+       acquire_fence_on(((size_t *)arc) - 1);
        ((void (*)(void *))destructor)(arc);
        free(((char *)arc) - 8);
 }
index 5ca8a82b3a470c386affc23e74c800764211c080..5c5f72e9c92b001ea4523c1444790d44a5397f9b 100644 (file)
--- a/src/arc.h
+++ b/src/arc.h
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/05/13 08:56:53 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/13 12:55:03 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/14 15:55:35 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
diff --git a/src/atomic.h b/src/atomic.h
new file mode 100644 (file)
index 0000000..c926672
--- /dev/null
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   atomic.h                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2026/05/15 11:18:31 by agilliar          #+#    #+#             */
+/*   Updated: 2026/05/15 11:23:58 by agilliar         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef ATOMIC_H
+# define ATOMIC_H
+
+# include <stddef.h>
+
+# if __has_feature(thread_sanitizer)
+
+__attribute__((always_inline))
+static inline void     acquire_fence_on(size_t *p)
+{
+       __atomic_load_n(p, __ATOMIC_ACQUIRE);
+}
+
+# else
+
+__attribute__((always_inline))
+static inline void     acquire_fence_on(size_t *p)
+{
+       (void) p;
+       __atomic_thread_fence(__ATOMIC_ACQUIRE);
+}
+
+# endif
+
+#endif
index 8602e02a01f2e9d02c96857144ca2355f34a25e6..e9a3dea14a6fecc8b0ea47fd0878404d8a9e856c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/04/29 16:08:57 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/14 14:58:03 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:21:51 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -21,6 +21,7 @@
 # include "arith.h"
 # include "arc.h"
 # include "stacktrack.h"
+# include "atomic.h"
 
 // The expression value is a tuple of an evaluatable and the argument to give it
 //
index 49778f9f06978e0bf4692a89ebf8ec678e7c18a9..c6b02db8cd556b2fb049b28c624bc0ec81b179cb 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/05/05 17:31:36 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/14 14:49:54 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:02:57 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
index 46748ec9529d0bc71f663dbdda48908c4fa18a4e..b06f9da3ce79e703eb0c977aa27cc5d13d5f1796 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/05/05 15:38:33 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/14 15:27:37 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:04:14 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
index 3310c833dc879eaad5ffc719c2c7eb36958138e3..65ddc8a06813a85dc77176c6df1c368e5e154cd3 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/05/14 12:00:36 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/14 15:33:45 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:04:26 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
index a80c8c7098e1e688d56d36d4a235eb1457dc3ebb..5fe591ec61bea5e1712f6baccac292c5e7acc8f1 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/05/13 22:04:36 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/13 22:08:57 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 13:05:11 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -39,16 +39,16 @@ typedef struct s_value
        enum e_value    tag;
 }      t_value;
 
-typedef struct s_bytes
+struct s_bytes
 {
        size_t  len;
        char    buf[];
-}      t_bytes;
+};
 
-typedef struct s_list
+struct s_list
 {
        size_t  len;
        t_value buf[];
-}      t_list;
+};
 
 #endif
diff --git a/test.c b/test.c
index fa9066c809df3a2b802c19db60b0bc1f2ee90f9a..21c539dc7488035832f686b47bc1f674badc27d7 100644 (file)
--- a/test.c
+++ b/test.c
@@ -6,7 +6,7 @@
 /*   By: agilliar <agilliar@student.42mulhouse.fr>  +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2026/04/30 17:19:58 by agilliar          #+#    #+#             */
-/*   Updated: 2026/05/14 15:45:14 by agilliar         ###   ########.fr       */
+/*   Updated: 2026/05/15 11:08:09 by agilliar         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include <stdio.h>
 #include <stdlib.h>
 
-void main2(char *orig)
+void main2(void        *_orig)
 {
-       char *s = malloc(strlen(orig) + 1);
+       char    *orig = _orig;
+       char    *s = malloc(strlen(orig) + 1);
        defer(free, s);
-       char *s2 = malloc(strlen(orig) + 1);
+       char    *s2 = malloc(strlen(orig) + 1);
        defer(free, s2);
        strcpy(s2, orig);
        printf("%s\n", s2);