There is no need for a name at runtime. The name is only necessary for you and the C compiler. The C compiler knows to which file it belongs, the file where it's defined. That's enough information.
Both variables are stored in the .bss section with their respective name, but at different memory locations. That's how their distinction is made.
You can confirm yourself how they are stored by using objdump
:
$ cat foo1.c
static int foo = 1;
$ cat foo2.c
static int foo = 2;
$ cat main.c
int main(void) { return 0; }
$ gcc -g -O0 -o foo foo1.c foo2.c main.c
$ objdump -d -j .data foo
test: file format elf64-x86-64
Disassembly of section .data:
00000000006008a8 <foo>:
6008a8: 01 00 00 00 ....
00000000006008ac <foo>:
6008ac: 02 00 00 00 ....