Skip to content

[libc] Fill out generated malloc.h and related stdlib.h extensions #127293

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

Merged
merged 2 commits into from
Feb 16, 2025

Conversation

frobtech
Copy link
Contributor

This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted. glibc's
extensions not implemented by Scudo are omitted. The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.

This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted.  glibc's
extensions not implemented by Scudo are omitted.  The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.
@frobtech frobtech requested review from Caslyn and fabio-d February 15, 2025 01:27
@frobtech frobtech marked this pull request as ready for review February 15, 2025 01:27
@llvmbot llvmbot added the libc label Feb 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 15, 2025

@llvm/pr-subscribers-libc

Author: Roland McGrath (frobtech)

Changes

This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted. glibc's
extensions not implemented by Scudo are omitted. The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.


Full diff: https://github.com/llvm/llvm-project/pull/127293.diff

3 Files Affected:

  • (modified) libc/include/malloc.yaml (+13)
  • (modified) libc/include/stdlib-malloc.yaml (+20-8)
  • (modified) libc/include/stdlib.yaml (+8)
diff --git a/libc/include/malloc.yaml b/libc/include/malloc.yaml
index bf7678797c023..cd84723557bcb 100644
--- a/libc/include/malloc.yaml
+++ b/libc/include/malloc.yaml
@@ -9,6 +9,12 @@ macros:
   - macro_name: M_PURGE_ALL
     macro_header: malloc-macros.h
 functions:
+  - name: malloc_usable_size
+    standards:
+      - gnu
+    return_type: size_t
+    arguments:
+      - type: void *
   - name: mallopt
     standards:
       - gnu
@@ -16,3 +22,10 @@ functions:
     arguments:
       - type: int
       - type: int
+  - name: pvalloc
+    standards:
+      - bsd
+      - gnu
+    return_type: void *
+    arguments:
+      - type: size_t
diff --git a/libc/include/stdlib-malloc.yaml b/libc/include/stdlib-malloc.yaml
index 648a6e58a90a0..51c11f5602e2c 100644
--- a/libc/include/stdlib-malloc.yaml
+++ b/libc/include/stdlib-malloc.yaml
@@ -1,4 +1,10 @@
 # This file has declarations that appear both in <stdlib.h> and in <malloc.h>.
+# These include the subset of GNU extensions that Scudo supports.
+#
+# Note: glibc's <stdlib.h> and <malloc.h> both also have `reallocarray`,
+# which Scudo does not support and is omitted here.  (Each of those glibc
+# headers also has related functions the other lacks, but those should be
+# covered separately in stdlib.yaml and malloc.yaml instead.)
 
 functions:
   - name: aligned_alloc
@@ -27,6 +33,13 @@ functions:
     return_type: void *
     arguments:
       - type: size_t
+  - name: memalign
+    standards:
+      - gnu
+    return_type: void *
+    arguments:
+      - type: size_t
+      - type: size_t
   - name: realloc
     standards:
       - stdc
@@ -34,11 +47,10 @@ functions:
     arguments:
       - type: void *
       - type: size_t
-
-# Note: glibc's <stdlib.h> and <malloc.h> both have these, which are
-# currently missing here:
-#  - name: reallocarray
-#  - name: memalign
-#  - name: valloc
-# Each of those glibc headers also has related functions the other lacks.
-# Only the common subset is mentioned here for future consideration.
+  - name: valloc
+    standards:
+      - bsd
+      - gnu
+    return_type: void *
+    arguments:
+      - type: size_t
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index 6ada26f020179..8d2b3f357e1a9 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -127,6 +127,14 @@ functions:
     arguments:
       - type: long long
       - type: long long
+  - name: posix_memalign
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: void **
+      - type: size_t
+      - type: size_t
   - name: qsort
     standards:
       - stdc

@frobtech frobtech merged commit ed48398 into llvm:main Feb 16, 2025
11 of 13 checks passed
@frobtech frobtech deleted the p/libc-malloc-decls branch February 16, 2025 00:32
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…lvm#127293)

This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted.  glibc's
extensions not implemented by Scudo are omitted.  The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants