Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
42 changes: 42 additions & 0 deletions libc/hdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ function(add_proxy_header_library target_name)
)
endfunction()

add_proxy_header_library(
aligned_alloc
HDRS
aligned_alloc.h
DEPENDS
.stdlib_overlay
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move this target after stdlib_overlay target.

FULL_BUILD_DEPENDS
libc.include.stdlib
)

add_proxy_header_library(
math_macros
HDRS
Expand Down Expand Up @@ -81,6 +91,8 @@ add_proxy_header_library(
libc.include.signal
)

add_header_library(stdlib_overlay HDRS stdlib_overlay.h)

add_proxy_header_library(
stdlib_macros
HDRS
Expand Down Expand Up @@ -152,6 +164,16 @@ add_proxy_header_library(
libc.include.float
)

add_proxy_header_library(
free
HDRS
free.h
DEPENDS
.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
)

add_proxy_header_library(
limits_macros
HDRS
Expand All @@ -170,6 +192,26 @@ add_proxy_header_library(
libc.include.link
)

add_proxy_header_library(
malloc
HDRS
malloc.h
DEPENDS
.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
)

add_proxy_header_library(
realloc
HDRS
realloc.h
DEPENDS
.stdlib_overlay
FULL_BUILD_DEPENDS
libc.include.stdlib
)

add_proxy_header_library(
sys_auxv_macros
HDRS
Expand Down
21 changes: 21 additions & 0 deletions libc/hdr/aligned_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of the aligned_alloc.h proxy ---------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_ALIGNED_ALLOC_H
#define LLVM_LIBC_HDR_ALIGNED_ALLOC_H

#ifdef LIBC_FULL_BUILD
extern "C" void *aligned_alloc(size_t, size_t);

#else // Overlay mode

#include "stdlib_overlay.h"

#endif

#endif
21 changes: 21 additions & 0 deletions libc/hdr/free.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of the free.h proxy ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_FREE_H
#define LLVM_LIBC_HDR_FREE_H

#ifdef LIBC_FULL_BUILD
extern "C" void free(void *);

#else // Overlay mode

#include "stdlib_overlay.h"

#endif

#endif
21 changes: 21 additions & 0 deletions libc/hdr/malloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of the malloc.h proxy ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_MALLOC_H
#define LLVM_LIBC_HDR_MALLOC_H

#ifdef LIBC_FULL_BUILD
extern "C" void *malloc(size_t);

#else // Overlay mode

#include "stdlib_overlay.h"

#endif

#endif
21 changes: 21 additions & 0 deletions libc/hdr/realloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Definition of the realloc.h proxy ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_HDR_REALLOC_H
#define LLVM_LIBC_HDR_REALLOC_H

#ifdef LIBC_FULL_BUILD
extern "C" void *realloc(void *ptr, size_t new_size);

#else // Overlay mode

#include "stdlib_overlay.h"

#endif

#endif
3 changes: 3 additions & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ add_header_library(
HDRS
char_vector.h
DEPENDS
libc.hdr.free
libc.hdr.malloc
libc.hdr.realloc
libc.src.__support.common
)

Expand Down
8 changes: 6 additions & 2 deletions libc/src/__support/CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ add_header_library(
HDRS
string.h
DEPENDS
libc.include.stdlib
.string_view
libc.hdr.free
libc.hdr.malloc
libc.hdr.realloc
libc.src.__support.common
libc.src.__support.integer_to_string
libc.src.string.memory_utils.inline_memcpy
Expand Down Expand Up @@ -199,7 +201,9 @@ add_object_library(
HDRS
new.h
DEPENDS
libc.include.stdlib
libc.hdr.free
libc.hdr.malloc
libc.hdr.aligned_alloc
libc.src.__support.common
libc.src.__support.macros.properties.os
)
2 changes: 1 addition & 1 deletion libc/src/__support/CPP/new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "new.h"
#include <stdlib.h> // For free, etc
#include "hdr/free.h"

void operator delete(void *mem) noexcept { ::free(mem); }

Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/CPP/new.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H

#include "hdr/aligned_alloc.h"
#include "hdr/free.h"
#include "hdr/malloc.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/os.h"

#include <stddef.h> // For size_t
#include <stdlib.h> // For malloc, free etc.

// Defining members in the std namespace is not preferred. But, we do it here
// so that we can use it to define the operator new which takes std::align_val_t
Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/CPP/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H
#define LLVM_LIBC_SRC___SUPPORT_CPP_STRING_H

#include "hdr/free.h"
#include "hdr/malloc.h"
#include "hdr/realloc.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/integer_to_string.h" // IntegerToString
#include "src/__support/macros/config.h"
Expand All @@ -17,7 +20,6 @@
#include "src/string/string_utils.h" // string_length

#include <stddef.h> // size_t
#include <stdlib.h> // malloc, free

namespace LIBC_NAMESPACE_DECL {
namespace cpp {
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/File/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_object_library(
libc.src.__support.error_or
libc.hdr.types.off_t
libc.hdr.stdio_macros
libc.hdr.realloc
)

add_object_library(
Expand Down
1 change: 1 addition & 0 deletions libc/src/__support/File/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "file.h"

#include "hdr/realloc.h"
#include "hdr/stdio_macros.h"
#include "hdr/types/off_t.h"
#include "src/__support/CPP/new.h"
Expand Down
4 changes: 3 additions & 1 deletion libc/src/__support/char_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H
#define LLVM_LIBC_SRC___SUPPORT_CHARVECTOR_H

#include "hdr/free.h"
#include "hdr/malloc.h"
#include "hdr/realloc.h"
#include "src/__support/common.h" // LIBC_INLINE
#include "src/__support/macros/config.h"

#include <stddef.h> // size_t
#include <stdlib.h> // malloc, realloc, free

namespace LIBC_NAMESPACE_DECL {

Expand Down
5 changes: 3 additions & 2 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ add_header_library(
HDRS
vasprintf_internal.h
DEPENDS
libc.hdr.malloc
libc.hdr.free
libc.hdr.realloc
libc.src.__support.arg_list
libc.src.stdio.printf_core.printf_main
libc.src.stdio.printf_core.writer
libc.src.stdlib.malloc
libc.src.stdlib.realloc
)

if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
Expand Down
4 changes: 3 additions & 1 deletion libc/src/stdio/printf_core/vasprintf_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "hdr/free.h"
#include "hdr/malloc.h"
#include "hdr/realloc.h"
#include "src/__support/arg_list.h"
#include "src/stdio/printf.h"
#include "src/stdio/printf_core/core_structs.h"
#include "src/stdio/printf_core/printf_main.h"
#include "src/stdio/printf_core/writer.h"
#include <stdlib.h> // malloc, realloc, free

namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
Expand Down
Loading