On Sun, Aug 15, 2021 at 9:30 AM Hamish MacDonald
<
hamish.m...@servian.com> wrote:
>
> I am trying to understand the implementation of os.Args().
>
> The os package says this is implemented in the runtime package
>
> file runtime.go contains:
> var argslice []string
>
> //go:linkname os_runtime_args os.runtime_args
> func os_runtime_args() []string { return append([]string{}, argslice...) }
>
> My question is:
>
> Where in the implementation is argslice populated?
If you grep for argslice in the runtime package sources you will see
that it is set by the goargs function based on argc and argv. argc
and argv are set by the function args, which is called by the startup
code which is written in assembler. For amd64/Linux you can see the
call to args from runtime·rt0_go in asm_amd64.s. The argc and argv
values are provided by the operating system when the program starts.
Ian