Module Name: src Committed By: riastradh Date: Sun Mar 30 16:17:05 UTC 2025
Modified Files: src/lib/libc: Makefile src/lib/libc/gen: ctype_guard.h Log Message: ctype(3): Actually conditionalize guard page on shared libc. Apparently we build the libc .o files with -fPIC too (I guess this is so that libc.a works in position-independent executables? but why don't they just use libc_pic.a?), so use a purpose-built cpp macro _CTYPE_DYNAMIC for this instead of using __PIC__. Now this shows the right symbol sizes: $ readelf -s ctype_.pico | grep _C_ctype_tab_guarded_ 3: 0000000000000000 4610 OBJECT LOCAL DEFAULT 11 _C_ctype_tab_guarded_ $ readelf -s ctype_.po | grep _C_ctype_tab_guarded_ 3: 0000000000000000 514 OBJECT LOCAL DEFAULT 7 _C_ctype_tab_guarded_ $ readelf -s ctype_.o | grep _C_ctype_tab_guarded_ 3: 0000000000000000 514 OBJECT LOCAL DEFAULT 7 _C_ctype_tab_guarded_ PR lib/58208: ctype(3) provides poor runtime feedback of abuse To generate a diff of this commit: cvs rdiff -u -r1.174 -r1.175 src/lib/libc/Makefile cvs rdiff -u -r1.4 -r1.5 src/lib/libc/gen/ctype_guard.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/Makefile diff -u src/lib/libc/Makefile:1.174 src/lib/libc/Makefile:1.175 --- src/lib/libc/Makefile:1.174 Mon May 29 18:25:52 2023 +++ src/lib/libc/Makefile Sun Mar 30 16:17:04 2025 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.174 2023/05/29 18:25:52 lukem Exp $ +# $NetBSD: Makefile,v 1.175 2025/03/30 16:17:04 riastradh Exp $ # @(#)Makefile 8.2 (Berkeley) 2/3/94 # # All library objects contain sccsid strings by default; they may be @@ -157,6 +157,10 @@ FILESDIR= /var/db # dlopen() from within statically linked binaries. CSHLIBFLAGS+= -D_I18N_DYNAMIC +# Tell ctype(3) that this is a dynamic libc, so if appropriate it +# should allocate a guard page. +CSHLIBFLAGS+= -D_CTYPE_DYNAMIC + .include <bsd.lib.mk> # force the dynamic linker to initialize libc first Index: src/lib/libc/gen/ctype_guard.h diff -u src/lib/libc/gen/ctype_guard.h:1.4 src/lib/libc/gen/ctype_guard.h:1.5 --- src/lib/libc/gen/ctype_guard.h:1.4 Sun Mar 30 15:38:38 2025 +++ src/lib/libc/gen/ctype_guard.h Sun Mar 30 16:17:05 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: ctype_guard.h,v 1.4 2025/03/30 15:38:38 riastradh Exp $ */ +/* $NetBSD: ctype_guard.h,v 1.5 2025/03/30 16:17:05 riastradh Exp $ */ /*- * Copyright (c) 2025 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ #if defined(__CHAR_UNSIGNED__) /* disable if char is unsigned */ # define _CTYPE_GUARD_PAGE 0 -#elif defined(__PIC__) /* enable in shared libc */ +#elif defined(_CTYPE_DYNAMIC) /* enable in shared libc */ # define _CTYPE_GUARD_PAGE 1 #else /* static libc -- let's aim for space-efficiency for now */ # define _CTYPE_GUARD_PAGE 0