All of lore.kernel.org
 help / color / mirror / Atom feed
* question about boot_params global variables
@ 2022-08-16  9:55 shiyu chou
  2022-08-17 10:04 ` Valentin Vidić
  2022-11-14 16:22 ` jim.cromie
  0 siblings, 2 replies; 5+ messages in thread
From: shiyu chou @ 2022-08-16  9:55 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 406 bytes --]

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?

[-- Attachment #1.2: Type: text/html, Size: 505 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about boot_params global variables
  2022-08-16  9:55 question about boot_params global variables shiyu chou
@ 2022-08-17 10:04 ` Valentin Vidić
  2022-11-14 16:22 ` jim.cromie
  1 sibling, 0 replies; 5+ messages in thread
From: Valentin Vidić @ 2022-08-17 10:04 UTC (permalink / raw)
  To: kernelnewbies

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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about boot_params global variables
  2022-08-16  9:55 question about boot_params global variables shiyu chou
  2022-08-17 10:04 ` Valentin Vidić
@ 2022-11-14 16:22 ` jim.cromie
  2022-11-14 18:41   ` Saad Masood
  1 sibling, 1 reply; 5+ messages in thread
From: jim.cromie @ 2022-11-14 16:22 UTC (permalink / raw)
  To: shiyu chou; +Cc: kernelnewbies

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about boot_params global variables
  2022-11-14 16:22 ` jim.cromie
@ 2022-11-14 18:41   ` Saad Masood
  2022-11-20 17:46     ` jim.cromie
  0 siblings, 1 reply; 5+ messages in thread
From: Saad Masood @ 2022-11-14 18:41 UTC (permalink / raw)
  To: jim.cromie; +Cc: shiyu chou, kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1273 bytes --]

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
>

[-- Attachment #1.2: Type: text/html, Size: 2175 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about boot_params global variables
  2022-11-14 18:41   ` Saad Masood
@ 2022-11-20 17:46     ` jim.cromie
  0 siblings, 0 replies; 5+ messages in thread
From: jim.cromie @ 2022-11-20 17:46 UTC (permalink / raw)
  To: Saad Masood; +Cc: shiyu chou, 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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-20 17:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16  9:55 question about boot_params global variables shiyu chou
2022-08-17 10:04 ` Valentin Vidić
2022-11-14 16:22 ` jim.cromie
2022-11-14 18:41   ` Saad Masood
2022-11-20 17:46     ` jim.cromie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.