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

tools/nolibc: add option to disable runtime

In principle, it is possible to use nolibc for only some object files in
a program. In that case, the startup code in _start and _start_c is not
going to be used. Add the NOLIBC_NO_RUNTIME compile time option to
disable it entirely and also remove anything that depends on it.

Doing this avoids warnings from modpost for UML as the _start_c code
references the main function from the .init.text section while it is not
inside .init itself.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

authored by

Benjamin Berg and committed by
Thomas Weißschuh
3d66c4e1 2cb6cc83

+36 -1
+2
tools/include/nolibc/arch-arm.h
··· 184 184 _arg1; \ 185 185 }) 186 186 187 + #ifndef NOLIBC_NO_RUNTIME 187 188 /* startup code */ 188 189 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 189 190 { ··· 194 193 ); 195 194 __nolibc_entrypoint_epilogue(); 196 195 } 196 + #endif /* NOLIBC_NO_RUNTIME */ 197 197 198 198 #endif /* _NOLIBC_ARCH_ARM_H */
+2
tools/include/nolibc/arch-arm64.h
··· 141 141 _arg1; \ 142 142 }) 143 143 144 + #ifndef NOLIBC_NO_RUNTIME 144 145 /* startup code */ 145 146 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 146 147 { ··· 151 150 ); 152 151 __nolibc_entrypoint_epilogue(); 153 152 } 153 + #endif /* NOLIBC_NO_RUNTIME */ 154 154 #endif /* _NOLIBC_ARCH_ARM64_H */
+2
tools/include/nolibc/arch-loongarch.h
··· 142 142 _arg1; \ 143 143 }) 144 144 145 + #ifndef NOLIBC_NO_RUNTIME 145 146 /* startup code */ 146 147 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 147 148 { ··· 152 151 ); 153 152 __nolibc_entrypoint_epilogue(); 154 153 } 154 + #endif /* NOLIBC_NO_RUNTIME */ 155 155 156 156 #endif /* _NOLIBC_ARCH_LOONGARCH_H */
+2
tools/include/nolibc/arch-m68k.h
··· 128 128 _num; \ 129 129 }) 130 130 131 + #ifndef NOLIBC_NO_RUNTIME 131 132 void _start(void); 132 133 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 133 134 { ··· 138 137 ); 139 138 __nolibc_entrypoint_epilogue(); 140 139 } 140 + #endif /* NOLIBC_NO_RUNTIME */ 141 141 142 142 #endif /* _NOLIBC_ARCH_M68K_H */
+2
tools/include/nolibc/arch-mips.h
··· 245 245 246 246 #endif /* _ABIO32 */ 247 247 248 + #ifndef NOLIBC_NO_RUNTIME 248 249 /* startup code, note that it's called __start on MIPS */ 249 250 void __start(void); 250 251 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void) ··· 267 266 ); 268 267 __nolibc_entrypoint_epilogue(); 269 268 } 269 + #endif /* NOLIBC_NO_RUNTIME */ 270 270 271 271 #endif /* _NOLIBC_ARCH_MIPS_H */
+2
tools/include/nolibc/arch-powerpc.h
··· 183 183 #endif 184 184 #endif /* !__powerpc64__ */ 185 185 186 + #ifndef NOLIBC_NO_RUNTIME 186 187 /* startup code */ 187 188 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 188 189 { ··· 216 215 #endif 217 216 __nolibc_entrypoint_epilogue(); 218 217 } 218 + #endif /* NOLIBC_NO_RUNTIME */ 219 219 220 220 #endif /* _NOLIBC_ARCH_POWERPC_H */
+2
tools/include/nolibc/arch-riscv.h
··· 139 139 _arg1; \ 140 140 }) 141 141 142 + #ifndef NOLIBC_NO_RUNTIME 142 143 /* startup code */ 143 144 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 144 145 { ··· 153 152 ); 154 153 __nolibc_entrypoint_epilogue(); 155 154 } 155 + #endif /* NOLIBC_NO_RUNTIME */ 156 156 157 157 #endif /* _NOLIBC_ARCH_RISCV_H */
+2
tools/include/nolibc/arch-s390.h
··· 139 139 _arg1; \ 140 140 }) 141 141 142 + #ifndef NOLIBC_NO_RUNTIME 142 143 /* startup code */ 143 144 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 144 145 { ··· 156 155 ); 157 156 __nolibc_entrypoint_epilogue(); 158 157 } 158 + #endif /* NOLIBC_NO_RUNTIME */ 159 159 160 160 struct s390_mmap_arg_struct { 161 161 unsigned long addr;
+2
tools/include/nolibc/arch-sh.h
··· 140 140 _ret; \ 141 141 }) 142 142 143 + #ifndef NOLIBC_NO_RUNTIME 143 144 /* startup code */ 144 145 void _start_wrapper(void); 145 146 void __attribute__((weak,noreturn)) __nolibc_entrypoint __no_stack_protector _start_wrapper(void) ··· 159 158 ); 160 159 __nolibc_entrypoint_epilogue(); 161 160 } 161 + #endif /* NOLIBC_NO_RUNTIME */ 162 162 163 163 #endif /* _NOLIBC_ARCH_SH_H */
+2
tools/include/nolibc/arch-sparc.h
··· 152 152 _arg1; \ 153 153 }) 154 154 155 + #ifndef NOLIBC_NO_RUNTIME 155 156 /* startup code */ 156 157 void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void) 157 158 { ··· 170 169 ); 171 170 __nolibc_entrypoint_epilogue(); 172 171 } 172 + #endif /* NOLIBC_NO_RUNTIME */ 173 173 174 174 static pid_t getpid(void); 175 175
+4
tools/include/nolibc/arch-x86.h
··· 157 157 _eax; \ 158 158 }) 159 159 160 + #ifndef NOLIBC_NO_RUNTIME 160 161 /* startup code */ 161 162 /* 162 163 * i386 System V ABI mandates: ··· 177 176 ); 178 177 __nolibc_entrypoint_epilogue(); 179 178 } 179 + #endif /* NOLIBC_NO_RUNTIME */ 180 180 181 181 #else /* !defined(__x86_64__) */ 182 182 ··· 325 323 _ret; \ 326 324 }) 327 325 326 + #ifndef NOLIBC_NO_RUNTIME 328 327 /* startup code */ 329 328 /* 330 329 * x86-64 System V ABI mandates: ··· 343 340 ); 344 341 __nolibc_entrypoint_epilogue(); 345 342 } 343 + #endif /* NOLIBC_NO_RUNTIME */ 346 344 347 345 #define NOLIBC_ARCH_HAS_MEMMOVE 348 346 void *memmove(void *dst, const void *src, size_t len);
+3
tools/include/nolibc/crt.h
··· 7 7 #ifndef _NOLIBC_CRT_H 8 8 #define _NOLIBC_CRT_H 9 9 10 + #ifndef NOLIBC_NO_RUNTIME 11 + 10 12 #include "compiler.h" 11 13 12 14 char **environ __attribute__((weak)); ··· 90 88 exit(exitcode); 91 89 } 92 90 91 + #endif /* NOLIBC_NO_RUNTIME */ 93 92 #endif /* _NOLIBC_CRT_H */
+2
tools/include/nolibc/stackprotector.h
··· 9 9 10 10 #include "compiler.h" 11 11 12 + #ifndef NOLIBC_NO_RUNTIME 12 13 #if defined(_NOLIBC_STACKPROTECTOR) 13 14 14 15 #include "sys.h" ··· 50 49 #else /* !defined(_NOLIBC_STACKPROTECTOR) */ 51 50 static void __stack_chk_init(void) {} 52 51 #endif /* defined(_NOLIBC_STACKPROTECTOR) */ 52 + #endif /* NOLIBC_NO_RUNTIME */ 53 53 54 54 #endif /* _NOLIBC_STACKPROTECTOR_H */
+2
tools/include/nolibc/stdlib.h
··· 100 100 munmap(heap, heap->len); 101 101 } 102 102 103 + #ifndef NOLIBC_NO_RUNTIME 103 104 /* getenv() tries to find the environment variable named <name> in the 104 105 * environment array pointed to by global variable "environ" which must be 105 106 * declared as a char **, and must be terminated by a NULL (it is recommended ··· 123 122 } 124 123 return NULL; 125 124 } 125 + #endif /* NOLIBC_NO_RUNTIME */ 126 126 127 127 static __attribute__((unused)) 128 128 void *malloc(size_t len)
+2 -1
tools/include/nolibc/sys.h
··· 512 512 return sys_gettid(); 513 513 } 514 514 515 + #ifndef NOLIBC_NO_RUNTIME 515 516 static unsigned long getauxval(unsigned long key); 516 517 517 518 /* ··· 524 523 { 525 524 return __sysret((int)getauxval(AT_PAGESZ) ?: -ENOENT); 526 525 } 527 - 526 + #endif /* NOLIBC_NO_RUNTIME */ 528 527 529 528 /* 530 529 * uid_t getuid(void);
+3
tools/include/nolibc/sys/auxv.h
··· 10 10 #ifndef _NOLIBC_SYS_AUXV_H 11 11 #define _NOLIBC_SYS_AUXV_H 12 12 13 + #ifndef NOLIBC_NO_RUNTIME 14 + 13 15 #include "../crt.h" 14 16 15 17 static __attribute__((unused)) ··· 40 38 return ret; 41 39 } 42 40 41 + #endif /* NOLIBC_NO_RUNTIME */ 43 42 #endif /* _NOLIBC_SYS_AUXV_H */