diff options
author | deraadt <> | 2025-05-23 00:40:05 +0000 |
---|---|---|
committer | deraadt <> | 2025-05-23 00:40:05 +0000 |
commit | db3d36558deff54e8a47e96933acd4543d7eb05f (patch) | |
tree | b340c64feaff7828e767291850aba4b7afa291a5 | |
parent | d6d6b23a49d21d2881e12b770fba4750c19047db (diff) | |
download | openbsd-db3d36558deff54e8a47e96933acd4543d7eb05f.tar.gz openbsd-db3d36558deff54e8a47e96933acd4543d7eb05f.tar.bz2 openbsd-db3d36558deff54e8a47e96933acd4543d7eb05f.zip |
When commons were deprecated, noone noticed that malloc_options in static
binaries had become unlinkable. Change the libc definition to weak to solve
that, and to "const char * const" so that noone will try to set it late.
It must be stable before the first malloc() call, which could be before
main()...
discussion with otto, kettenis, tedu
-rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 9 | ||||
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index bea5575bf8..b0c6fb782b 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
@@ -30,9 +30,9 @@ | |||
30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
32 | .\" | 32 | .\" |
33 | .\" $OpenBSD: malloc.3,v 1.142 2024/08/03 20:09:24 guenther Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.143 2025/05/23 00:40:05 deraadt Exp $ |
34 | .\" | 34 | .\" |
35 | .Dd $Mdocdate: August 3 2024 $ | 35 | .Dd $Mdocdate: May 23 2025 $ |
36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
37 | .Os | 37 | .Os |
38 | .Sh NAME | 38 | .Sh NAME |
@@ -69,7 +69,8 @@ | |||
69 | .Fn malloc_conceal "size_t size" | 69 | .Fn malloc_conceal "size_t size" |
70 | .Ft void * | 70 | .Ft void * |
71 | .Fn calloc_conceal "size_t nmemb" "size_t size" | 71 | .Fn calloc_conceal "size_t nmemb" "size_t size" |
72 | .Vt char *malloc_options ; | 72 | .Vt const char * const |
73 | .Va malloc_options ; | ||
73 | .Sh DESCRIPTION | 74 | .Sh DESCRIPTION |
74 | The standard functions | 75 | The standard functions |
75 | .Fn malloc , | 76 | .Fn malloc , |
@@ -265,7 +266,7 @@ value of the | |||
265 | .Xr sysctl 2 , | 266 | .Xr sysctl 2 , |
266 | next checks the environment for a variable called | 267 | next checks the environment for a variable called |
267 | .Ev MALLOC_OPTIONS , | 268 | .Ev MALLOC_OPTIONS , |
268 | and finally looks at the global variable | 269 | and finally looks at the pre-initialized global variable |
269 | .Va malloc_options | 270 | .Va malloc_options |
270 | in the program. | 271 | in the program. |
271 | Each is scanned for the flags documented below. | 272 | Each is scanned for the flags documented below. |
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index cad8e5d6a1..fa36a3a7f3 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.297 2024/09/20 02:00:46 jsg Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.298 2025/05/23 00:40:05 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> |
4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
@@ -264,7 +264,8 @@ static union { | |||
264 | __attribute__((section(".openbsd.mutable"))); | 264 | __attribute__((section(".openbsd.mutable"))); |
265 | #define mopts malloc_readonly.mopts | 265 | #define mopts malloc_readonly.mopts |
266 | 266 | ||
267 | char *malloc_options; /* compile-time options */ | 267 | /* compile-time options */ |
268 | const char *const malloc_options __attribute__((weak)); | ||
268 | 269 | ||
269 | static __dead void wrterror(struct dir_info *d, char *msg, ...) | 270 | static __dead void wrterror(struct dir_info *d, char *msg, ...) |
270 | __attribute__((__format__ (printf, 2, 3))); | 271 | __attribute__((__format__ (printf, 2, 3))); |
@@ -501,7 +502,8 @@ omalloc_parseopt(char opt) | |||
501 | static void | 502 | static void |
502 | omalloc_init(void) | 503 | omalloc_init(void) |
503 | { | 504 | { |
504 | char *p, *q, b[16]; | 505 | const char *p; |
506 | char *q, b[16]; | ||
505 | int i, j; | 507 | int i, j; |
506 | const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; | 508 | const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; |
507 | size_t sb; | 509 | size_t sb; |