Просмотр исходного кода

limits.h: define PAGE_SIZE/PAGESIZE like musl, fixing the gdb build

Commit 487af1498 ("drop __pagesize, make _dl_pagesize the single source
of truth") removed the compile-time PAGE_SIZE / PAGE_MASK macros from
<bits/uClibc_page.h> (and from i386 <sys/user.h>) so that libc internals
can no longer use a fixed page size before _dl_pagesize is initialised.
That is correct for libc-internal code, but PAGE_SIZE is also a public
compile-time macro that third-party software relies on: glibc exposes it
from <sys/user.h>, musl from <limits.h>.  gdb's gdb/nat/linux-btrace.c,
for example, uses PAGE_SIZE with no fallback, so gdbserver no longer
builds on uClibc-ng:

  linux-btrace.c:549:34: error: 'PAGE_SIZE' was not declared in this scope

Restore it the way musl does.  PAGE_SIZE (and PAGESIZE) are now defined
centrally in <limits.h>, gated on _GNU_SOURCE / _BSD_SOURCE /
_XOPEN_SOURCE, and derived from the per-architecture PAGE_SHIFT that
<bits/uClibc_page.h> still provides.  The page headers keep only
PAGE_SHIFT as the single source of truth, so the macro never reaches the
libc-internal code that includes <bits/uClibc_page.h> -- the init-order
trap that 487af1498 closed stays closed -- while public, feature-test
gated code gets the constant back.

As part of the same move the competing per-arch PAGE_SIZE / PAGE_MASK
definitions are dropped, and the obsolete BFD trad-core block
(NBPG / UPAGES / HOST_*_ADDR / SUNOS_CORE_MAGIC) is removed from the
remaining sys/user.h files (alpha, m68k, microblaze, mips, nds32, sh,
sparc, sparc64, x86_64).  This completes commit 62cb84000
("sys/user.h: remove obsolete BFD trad-core NBPG/UPAGES defines"), which
did i386/nios2/ia64/bfin; the symbols have no in-tree users.

Verified with the preprocessor: with _GNU_SOURCE (and with the default
_BSD_SOURCE, and with _XOPEN_SOURCE) PAGE_SIZE expands to (1UL << 12) on
i386/x86_64/arm and to (1UL << 13) on cris/alpha; under -ansi it is
absent.

Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
Ramin Moussavi 1 неделя назад
Родитель
Сommit
0357e28fe4

+ 13 - 0
include/limits.h

@@ -151,3 +151,16 @@
 #ifdef	__USE_XOPEN
 # include <bits/xopen_lim.h>
 #endif
+
+/* Page size as a compile-time constant, defined centrally like musl and
+   gated on the same feature macros; the run-time value is getpagesize()
+   / sysconf(_SC_PAGESIZE).  PAGE_SHIFT comes from <bits/uClibc_page.h>.  */
+#if defined __USE_MISC || defined __USE_XOPEN || defined __USE_GNU
+# include <bits/uClibc_page.h>
+# ifndef PAGESIZE
+#  define PAGESIZE	(1UL << PAGE_SHIFT)
+# endif
+# ifndef PAGE_SIZE
+#  define PAGE_SIZE	PAGESIZE
+# endif
+#endif

+ 0 - 2
libc/sysdeps/linux/aarch64/bits/uClibc_page.h

@@ -19,7 +19,5 @@
 #define PAGE_SHIFT		12
 #endif
 
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 2
libc/sysdeps/linux/alpha/bits/uClibc_page.h

@@ -22,7 +22,5 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 8192 */
 #define PAGE_SHIFT	13
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 7
libc/sysdeps/linux/alpha/sys/user.h

@@ -22,7 +22,6 @@
    only. Don't read too much into it. Don't use it for anything other
    than gdb/strace unless you know what you are doing. */
 
-#include <bits/uClibc_page.h>
 #include <asm/reg.h>
 
 struct user
@@ -40,10 +39,4 @@ struct user
   char u_comm[32];				/* user command name */
 };
 
-#define NBPG			PAGE_SIZE
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_DATA_START_ADDR	(u.start_data)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif	/* sys/user.h */

+ 0 - 2
libc/sysdeps/linux/arc/bits/uClibc_page.h

@@ -26,8 +26,6 @@
 #define PAGE_SHIFT		13
 #endif
 
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 /* TBD: fix this with runtime value for a PAGE_SIZE agnostic uClibc */
 #define MMAP2_PAGE_SHIFT PAGE_SHIFT

+ 0 - 2
libc/sysdeps/linux/cris/bits/uClibc_page.h

@@ -22,8 +22,6 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 8192 */
 #define PAGE_SHIFT	13
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 /* Some architectures always use 12 as page shift for mmap2() eventhough the
  * real PAGE_SHIFT != 12.  Other architectures use the same value as

+ 0 - 6
libc/sysdeps/linux/frv/bits/uClibc_page.h

@@ -22,11 +22,5 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 4096 */
 #define PAGE_SHIFT	(14)
-#ifndef __ASSEMBLY__
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#else
-#define PAGE_SIZE	(1 << PAGE_SHIFT)
-#endif
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 2
libc/sysdeps/linux/lm32/bits/uClibc_page.h

@@ -19,7 +19,5 @@
 #define _UCLIBC_PAGE_H
 
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 2
libc/sysdeps/linux/m68k/bits/uClibc_page.h

@@ -35,7 +35,5 @@
 #define PAGE_SHIFT	(13)
 #endif
 */
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 4
libc/sysdeps/linux/m68k/sys/user.h

@@ -82,9 +82,5 @@ struct user{
   unsigned long magic;		/* To uniquely identify a core file */
   char u_comm[32];		/* User command that was responsible */
 };
-#define NBPG 4096
-#define UPAGES 1
-#define HOST_TEXT_START_ADDR (u.start_code)
-#define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG)
 
 #endif

+ 0 - 2
libc/sysdeps/linux/microblaze/bits/uClibc_page.h

@@ -21,7 +21,5 @@
 #define _UCLIBC_PAGE_H
 
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 8
libc/sysdeps/linux/microblaze/sys/user.h

@@ -65,12 +65,4 @@ struct user
   int				u_debugreg [8];
 };
 
-#define PAGE_SHIFT		12
-#define PAGE_SIZE		(1UL << PAGE_SHIFT)
-#define PAGE_MASK		(~(PAGE_SIZE-1))
-#define NBPG			PAGE_SIZE
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif	/* _SYS_USER_H */

+ 0 - 2
libc/sysdeps/linux/mips/bits/uClibc_page.h

@@ -29,7 +29,5 @@
 #define PAGE_SHIFT	14
 #endif
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 7
libc/sysdeps/linux/mips/sys/user.h

@@ -206,11 +206,4 @@ struct user {
 
 #endif
 
-#include <bits/uClibc_page.h>
-#define NBPG			PAGE_SIZE
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_DATA_START_ADDR	(u.start_data)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif	/* _SYS_USER_H */

+ 0 - 2
libc/sysdeps/linux/nds32/bits/uClibc_page.h

@@ -22,8 +22,6 @@
 #define PAGE_SHIFT		12
 #endif
 
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 /* TBD: fix this with runtime value for a PAGE_SIZE agnostic uClibc */
 #define MMAP2_PAGE_SHIFT PAGE_SHIFT

+ 0 - 7
libc/sysdeps/linux/nds32/sys/user.h

@@ -73,11 +73,4 @@ struct user
   struct user_fpregs *u_fp0;	/* help gdb to find the FP registers. */
 };
 
-#include <bits/uClibc_page.h>
-#define NBPG			PAGE_SIZE
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_DATA_START_ADDR	(u.start_data)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif  /* sys/user.h */

+ 0 - 2
libc/sysdeps/linux/or1k/bits/uClibc_page.h

@@ -22,8 +22,6 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 4096 */
 #define PAGE_SHIFT	13
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 /* Some architectures always use 12 as page shift for mmap2() eventhough the
  * real PAGE_SHIFT != 12.  Other architectures use the same value as

+ 0 - 2
libc/sysdeps/linux/riscv32/bits/uClibc_page.h

@@ -22,7 +22,5 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 4096 */
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #endif /* _UCLIBC_PAGE_H */

+ 0 - 2
libc/sysdeps/linux/riscv64/bits/uClibc_page.h

@@ -22,8 +22,6 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 4096 */
 #define PAGE_SHIFT	12
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 /* Some architectures always use 12 as page shift for mmap2() eventhough the
  * real PAGE_SHIFT != 12.  Other architectures use the same value as

+ 0 - 6
libc/sysdeps/linux/sh/sys/user.h

@@ -79,10 +79,4 @@ struct user {
 	char		u_comm[32];		/* user command name */
 };
 
-#define NBPG			getpagesize()
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_DATA_START_ADDR	(u.start_data)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif  /* sys/user.h */

+ 0 - 4
libc/sysdeps/linux/sparc/sys/user.h

@@ -77,8 +77,4 @@ struct user {
   unsigned int  sigcode;
 };
 
-#define NBPG			0x2000
-#define UPAGES			1
-#define SUNOS_CORE_MAGIC	0x080456
-
 #endif

+ 0 - 2
libc/sysdeps/linux/sparc64/bits/uClibc_page.h

@@ -9,8 +9,6 @@
 
 /* PAGE_SHIFT determines the page size -- in this case 8192 */
 #define PAGE_SHIFT	13
-#define PAGE_SIZE	(1UL << PAGE_SHIFT)
-#define PAGE_MASK	(~(PAGE_SIZE-1))
 
 #define MMAP2_PAGE_SHIFT PAGE_SHIFT
 

+ 0 - 4
libc/sysdeps/linux/sparc64/sys/user.h

@@ -76,8 +76,4 @@ struct user {
   unsigned int  sigcode;
 };
 
-#define NBPG			0x2000
-#define UPAGES			1
-#define SUNOS_CORE_MAGIC	0x080456
-
 #endif

+ 0 - 9
libc/sysdeps/linux/x86_64/sys/user.h

@@ -163,13 +163,4 @@ struct user
 };
 #endif  /* __WORDSIZE */
 
-#include <bits/uClibc_page.h>
-#define PAGE_SHIFT		12
-#define PAGE_SIZE		(1UL << PAGE_SHIFT)
-#define PAGE_MASK		(~(PAGE_SIZE-1))
-#define NBPG			PAGE_SIZE
-#define UPAGES			1
-#define HOST_TEXT_START_ADDR	(u.start_code)
-#define HOST_STACK_END_ADDR	(u.start_stack + u.u_ssize * NBPG)
-
 #endif	/* _SYS_USER_H */