Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

asm-generic: Unify uapi bitsperlong.h for arm64, riscv and loongarch

Now we specify the minimal version of GCC as 5.1 and Clang/LLVM as 11.0.0
in Documentation/process/changes.rst, __CHAR_BIT__ and __SIZEOF_LONG__ are
usable, it is probably fine to unify the definition of __BITS_PER_LONG as
(__CHAR_BIT__ * __SIZEOF_LONG__) in asm-generic uapi bitsperlong.h.

In order to keep safe and avoid regression, only unify uapi bitsperlong.h
for some archs such as arm64, riscv and loongarch which are using newer
toolchains that have the definitions of __CHAR_BIT__ and __SIZEOF_LONG__.

Suggested-by: Xi Ruoyao <xry111@xry111.site>
Link: https://lore.kernel.org/all/d3e255e4746de44c9903c4433616d44ffcf18d1b.camel@xry111.site/
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/linux-arch/a3a4f48a-07d4-4ed9-bc53-5d383428bdd2@app.fastmail.com/
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

authored by

Tiezhu Yang and committed by
Arnd Bergmann
8386f58f 3b1ddbb6

+25 -102
-24
arch/arm64/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - /* 3 - * Copyright (C) 2012 ARM Ltd. 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License version 2 as 7 - * published by the Free Software Foundation. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 - */ 17 - #ifndef __ASM_BITSPERLONG_H 18 - #define __ASM_BITSPERLONG_H 19 - 20 - #define __BITS_PER_LONG 64 21 - 22 - #include <asm-generic/bitsperlong.h> 23 - 24 - #endif /* __ASM_BITSPERLONG_H */
-9
arch/loongarch/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - #ifndef __ASM_LOONGARCH_BITSPERLONG_H 3 - #define __ASM_LOONGARCH_BITSPERLONG_H 4 - 5 - #define __BITS_PER_LONG (__SIZEOF_LONG__ * 8) 6 - 7 - #include <asm-generic/bitsperlong.h> 8 - 9 - #endif /* __ASM_LOONGARCH_BITSPERLONG_H */
-14
arch/riscv/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 2 - /* 3 - * Copyright (C) 2012 ARM Ltd. 4 - * Copyright (C) 2015 Regents of the University of California 5 - */ 6 - 7 - #ifndef _UAPI_ASM_RISCV_BITSPERLONG_H 8 - #define _UAPI_ASM_RISCV_BITSPERLONG_H 9 - 10 - #define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8) 11 - 12 - #include <asm-generic/bitsperlong.h> 13 - 14 - #endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
+12 -1
include/uapi/asm-generic/bitsperlong.h
··· 2 2 #ifndef _UAPI__ASM_GENERIC_BITS_PER_LONG 3 3 #define _UAPI__ASM_GENERIC_BITS_PER_LONG 4 4 5 + #ifndef __BITS_PER_LONG 6 + /* 7 + * In order to keep safe and avoid regression, only unify uapi 8 + * bitsperlong.h for some archs which are using newer toolchains 9 + * that have the definitions of __CHAR_BIT__ and __SIZEOF_LONG__. 10 + * See the following link for more info: 11 + * https://lore.kernel.org/linux-arch/b9624545-2c80-49a1-ac3c-39264a591f7b@app.fastmail.com/ 12 + */ 13 + #if defined(__CHAR_BIT__) && defined(__SIZEOF_LONG__) 14 + #define __BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__) 15 + #else 5 16 /* 6 17 * There seems to be no way of detecting this automatically from user 7 18 * space, so 64 bit architectures should override this in their ··· 20 9 * both 32 and 64 bit user space must not rely on CONFIG_64BIT 21 10 * to decide it, but rather check a compiler provided macro. 22 11 */ 23 - #ifndef __BITS_PER_LONG 24 12 #define __BITS_PER_LONG 32 13 + #endif 25 14 #endif 26 15 27 16 #endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */
-24
tools/arch/arm64/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - /* 3 - * Copyright (C) 2012 ARM Ltd. 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License version 2 as 7 - * published by the Free Software Foundation. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 - * GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 - */ 17 - #ifndef __ASM_BITSPERLONG_H 18 - #define __ASM_BITSPERLONG_H 19 - 20 - #define __BITS_PER_LONG 64 21 - 22 - #include <asm-generic/bitsperlong.h> 23 - 24 - #endif /* __ASM_BITSPERLONG_H */
-9
tools/arch/loongarch/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 - #ifndef __ASM_LOONGARCH_BITSPERLONG_H 3 - #define __ASM_LOONGARCH_BITSPERLONG_H 4 - 5 - #define __BITS_PER_LONG (__SIZEOF_LONG__ * 8) 6 - 7 - #include <asm-generic/bitsperlong.h> 8 - 9 - #endif /* __ASM_LOONGARCH_BITSPERLONG_H */
-14
tools/arch/riscv/include/uapi/asm/bitsperlong.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 2 - /* 3 - * Copyright (C) 2012 ARM Ltd. 4 - * Copyright (C) 2015 Regents of the University of California 5 - */ 6 - 7 - #ifndef _UAPI_ASM_RISCV_BITSPERLONG_H 8 - #define _UAPI_ASM_RISCV_BITSPERLONG_H 9 - 10 - #define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8) 11 - 12 - #include <asm-generic/bitsperlong.h> 13 - 14 - #endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
+13 -1
tools/include/uapi/asm-generic/bitsperlong.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 1 2 #ifndef _UAPI__ASM_GENERIC_BITS_PER_LONG 2 3 #define _UAPI__ASM_GENERIC_BITS_PER_LONG 3 4 5 + #ifndef __BITS_PER_LONG 6 + /* 7 + * In order to keep safe and avoid regression, only unify uapi 8 + * bitsperlong.h for some archs which are using newer toolchains 9 + * that have the definitions of __CHAR_BIT__ and __SIZEOF_LONG__. 10 + * See the following link for more info: 11 + * https://lore.kernel.org/linux-arch/b9624545-2c80-49a1-ac3c-39264a591f7b@app.fastmail.com/ 12 + */ 13 + #if defined(__CHAR_BIT__) && defined(__SIZEOF_LONG__) 14 + #define __BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__) 15 + #else 4 16 /* 5 17 * There seems to be no way of detecting this automatically from user 6 18 * space, so 64 bit architectures should override this in their ··· 20 8 * both 32 and 64 bit user space must not rely on CONFIG_64BIT 21 9 * to decide it, but rather check a compiler provided macro. 22 10 */ 23 - #ifndef __BITS_PER_LONG 24 11 #define __BITS_PER_LONG 32 12 + #endif 25 13 #endif 26 14 27 15 #endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */
-6
tools/include/uapi/asm/bitsperlong.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 #if defined(__i386__) || defined(__x86_64__) 3 3 #include "../../../arch/x86/include/uapi/asm/bitsperlong.h" 4 - #elif defined(__aarch64__) 5 - #include "../../../arch/arm64/include/uapi/asm/bitsperlong.h" 6 4 #elif defined(__powerpc__) 7 5 #include "../../../arch/powerpc/include/uapi/asm/bitsperlong.h" 8 6 #elif defined(__s390__) ··· 11 13 #include "../../../arch/mips/include/uapi/asm/bitsperlong.h" 12 14 #elif defined(__ia64__) 13 15 #include "../../../arch/ia64/include/uapi/asm/bitsperlong.h" 14 - #elif defined(__riscv) 15 - #include "../../../arch/riscv/include/uapi/asm/bitsperlong.h" 16 16 #elif defined(__alpha__) 17 17 #include "../../../arch/alpha/include/uapi/asm/bitsperlong.h" 18 - #elif defined(__loongarch__) 19 - #include "../../../arch/loongarch/include/uapi/asm/bitsperlong.h" 20 18 #else 21 19 #include <asm-generic/bitsperlong.h> 22 20 #endif