question about boot_params global variables
Hello all: In arch x86 directory I found two global variables with the same name(master branch): 1.arch/x86/boot/main.c near line 18: struct boot_params boot_params __attribute__((aligned(16))); 2.arch/x86/kernel/setup.c near line 75: struct boot_params boot_params; Is that wrong to define two global variables with the same name? And when use extern to reference the variable,which one did it reference?
On Tue, Aug 16, 2022 at 05:55:33PM +0800, shiyu chou wrote:
In arch x86 directory I found two global variables with the same name(master branch): 1.arch/x86/boot/main.c near line 18: struct boot_params boot_params __attribute__((aligned(16))); 2.arch/x86/kernel/setup.c near line 75: struct boot_params boot_params; Is that wrong to define two global variables with the same name? And when use extern to reference the variable,which one did it reference?
Same name would be a problem if these two variables end up in the same binary program. However, as the comment in arch/x86/boot/main.c suggests: /* * Main module for the real-mode kernel code */ first variable is part of a small real-mode kernel that runs first. It finishes running by switching to the protected mode kernel that contains the second variable: protected_mode_jump(boot_params.hdr.code32_start, (u32)&boot_params + (ds() << 4)); For more details see https://www.kernel.org/doc/html/latest/x86/boot.html -- Valentin
On Tue, Aug 16, 2022 at 4:10 AM shiyu chou <shiyu2010310@gmail.com> wrote:
Hello all: In arch x86 directory I found two global variables with the same name(master branch): 1.arch/x86/boot/main.c near line 18: struct boot_params boot_params __attribute__((aligned(16))); 2.arch/x86/kernel/setup.c near line 75: struct boot_params boot_params; Is that wrong to define two global variables with the same name? And when use extern to reference the variable,which one did it reference?
hi, did you figure out a satisfactory answer ? what happens when you build with W=1 ?
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Jim, In C, two global variables with the same name are converted to one global variable (same memory address space). So, the same variable is referenced with or without the 'extern' keyword. Thanks, Saad On Mon, Nov 14, 2022 at 11:23 AM <jim.cromie@gmail.com> wrote:
On Tue, Aug 16, 2022 at 4:10 AM shiyu chou <shiyu2010310@gmail.com> wrote:
Hello all: In arch x86 directory I found two global variables with the same
name(master branch):
1.arch/x86/boot/main.c near line 18: struct boot_params boot_params __attribute__((aligned(16))); 2.arch/x86/kernel/setup.c near line 75: struct boot_params boot_params; Is that wrong to define two global variables with the same name? And when use extern to reference the variable,which one did it reference?
hi, did you figure out a satisfactory answer ?
what happens when you build with W=1 ?
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Mon, Nov 14, 2022 at 11:41 AM Saad Masood <saadahmed42@gmail.com> wrote:
Hi Jim, In C, two global variables with the same name are converted to one global variable (same memory address space). So, the same variable is referenced with or without the 'extern' keyword.
Thanks,
thanks Saad, its nice when a thread reaches a tight conclusion.
Saad
On Mon, Nov 14, 2022 at 11:23 AM <jim.cromie@gmail.com> wrote:
On Tue, Aug 16, 2022 at 4:10 AM shiyu chou <shiyu2010310@gmail.com> wrote:
Hello all: In arch x86 directory I found two global variables with the same name(master branch): 1.arch/x86/boot/main.c near line 18: struct boot_params boot_params __attribute__((aligned(16))); 2.arch/x86/kernel/setup.c near line 75: struct boot_params boot_params; Is that wrong to define two global variables with the same name? And when use extern to reference the variable,which one did it reference?
hi, did you figure out a satisfactory answer ?
what happens when you build with W=1 ?
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (4)
-
jim.cromie@gmail.com -
Saad Masood -
shiyu chou -
Valentin Vidić