Compile libc with -ffreestanding.
This properly avoids problems where the compiler is unaware that this is the implementation and assumes it can rely on the implementation. For instance, it might implement calloc using a call to calloc. Restructure the code that wrongly assumed __STDC_HOSTED__ meant userspace.
This commit is contained in:
parent
1ca1a068a1
commit
01a9779fc6
10 changed files with 26 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2013, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
#include <__/pthread.h>
|
#include <__/pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
#ifndef __pthread_attr_t_defined
|
#ifndef __pthread_attr_t_defined
|
||||||
#define __pthread_attr_t_defined
|
#define __pthread_attr_t_defined
|
||||||
typedef __pthread_attr_t pthread_attr_t;
|
typedef __pthread_attr_t pthread_attr_t;
|
||||||
|
@ -49,7 +49,7 @@ struct sigevent
|
||||||
int sigev_signo;
|
int sigev_signo;
|
||||||
union sigval sigev_value;
|
union sigval sigev_value;
|
||||||
void (*sigev_notify_function)(union sigval);
|
void (*sigev_notify_function)(union sigval);
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
pthread_attr_t* sigev_notify_attributes;
|
pthread_attr_t* sigev_notify_attributes;
|
||||||
#else
|
#else
|
||||||
void* sigev_notify_attributes;
|
void* sigev_notify_attributes;
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
@ -10,7 +10,7 @@ CPUDIR:=$(CPU)
|
||||||
|
|
||||||
CPPINCLUDES=-Iinclude
|
CPPINCLUDES=-Iinclude
|
||||||
CPPFLAGS=-D__is_sortix_libc $(CPPINCLUDES)
|
CPPFLAGS=-D__is_sortix_libc $(CPPINCLUDES)
|
||||||
FLAGS=-Wall -Wextra $(OPTLEVEL)
|
FLAGS=-Wall -Wextra -ffreestanding $(OPTLEVEL)
|
||||||
CFLAGS=-std=gnu11 -Wstrict-prototypes -Werror=implicit-function-declaration
|
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
|
||||||
ASFLAGS=
|
ASFLAGS=
|
||||||
|
@ -740,7 +740,7 @@ HEADERS:=$(shell find include -type f)
|
||||||
|
|
||||||
LIBK_OBJS:=$(FREEOBJS:.o=.libk.o)
|
LIBK_OBJS:=$(FREEOBJS:.o=.libk.o)
|
||||||
LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libk
|
LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libk
|
||||||
LIBK_FLAGS:=$(FLAGS) -ffreestanding
|
LIBK_FLAGS:=$(FLAGS)
|
||||||
LIBK_CFLAGS:=$(CFLAGS)
|
LIBK_CFLAGS:=$(CFLAGS)
|
||||||
LIBK_CXXFLAGS:=$(CXXFLAGS)
|
LIBK_CXXFLAGS:=$(CXXFLAGS)
|
||||||
ifeq ($(HOST),x86_64-sortix)
|
ifeq ($(HOST),x86_64-sortix)
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#ifndef __is_sortix_libk
|
||||||
|
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
void* operator new(size_t size)
|
void* operator new(size_t size)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -117,7 +117,7 @@ extern "C" {
|
||||||
|
|
||||||
#define EOPNOTSUPP ENOTSUP
|
#define EOPNOTSUPP ENOTSUP
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
|
|
||||||
extern __thread int errno;
|
extern __thread int errno;
|
||||||
#define errno errno
|
#define errno errno
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -74,17 +74,17 @@ int heap_get_paranoia(void);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(HEAP_GUARD_DEBUG) && \
|
#ifdef __is_sortix_libk
|
||||||
defined(__is_sortix_kernel) && defined(HEAP_GUARD_DEBUG_KERNEL)
|
#if !defined(HEAP_GUARD_DEBUG) && defined(HEAP_GUARD_DEBUG_KERNEL)
|
||||||
#define HEAP_GUARD_DEBUG
|
#define HEAP_GUARD_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
#if !defined(MALLOC_GUARD_DEBUG) && \
|
#if !defined(MALLOC_GUARD_DEBUG) && defined(HEAP_GUARD_DEBUG_USERLAND)
|
||||||
__STDC_HOSTED__ && defined(HEAP_GUARD_DEBUG_USERLAND)
|
|
||||||
#define HEAP_GUARD_DEBUG
|
#define HEAP_GUARD_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HEAP_GUARD_DEBUG) && !defined(__is_sortix_kernel)
|
#if defined(HEAP_GUARD_DEBUG) && !defined(__is_sortix_libk)
|
||||||
struct heap_alloc
|
struct heap_alloc
|
||||||
{
|
{
|
||||||
uintptr_t from;
|
uintptr_t from;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2013, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -52,7 +52,7 @@ static __inline uint64_t wrmsr_instruction(uint32_t msrid, uint64_t value)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
|
|
||||||
uint64_t rdmsr(uint32_t msrid);
|
uint64_t rdmsr(uint32_t msrid);
|
||||||
uint64_t wrmsr(uint32_t msrid, uint64_t value);
|
uint64_t wrmsr(uint32_t msrid, uint64_t value);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include <sys/__/types.h>
|
#include <sys/__/types.h>
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
#include <__/pthread.h>
|
#include <__/pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ typedef __pid_t pid_t;
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
|
|
||||||
#ifndef __pthread_attr_t_defined
|
#ifndef __pthread_attr_t_defined
|
||||||
#define __pthread_attr_t_defined
|
#define __pthread_attr_t_defined
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
#ifndef INCLUDE_SYS_SYSCALL_H
|
#ifndef INCLUDE_SYS_SYSCALL_H
|
||||||
#define INCLUDE_SYS_SYSCALL_H
|
#define INCLUDE_SYS_SYSCALL_H
|
||||||
|
|
||||||
#if !__STDC_HOSTED__
|
#ifdef __is_sortix_libk
|
||||||
#error "This file is part of user-space and should not be built into libk"
|
#error "This file is part of user-space and should not be built into libk"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#include <sys/__/types.h>
|
#include <sys/__/types.h>
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
#include <__/pthread.h>
|
#include <__/pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ typedef __uid_t uid_t;
|
||||||
#define SCNxUID __SCNxUID
|
#define SCNxUID __SCNxUID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __STDC_HOSTED__
|
#if !defined(__is_sortix_libk) && !defined(__is_sortix_kernel)
|
||||||
|
|
||||||
#ifndef __pthread_attr_t_defined
|
#ifndef __pthread_attr_t_defined
|
||||||
#define __pthread_attr_t_defined
|
#define __pthread_attr_t_defined
|
||||||
|
|
Loading…
Reference in a new issue