In Clang or LLVM, how to properly declare an external variable that refers to a CPU register? For example, I would like to express the following declarations (as in https://github.com/mit-pdos/xv6-public/blob/master/proc.h#L27):
extern struct cpu *cpu asm("%gs:0"); // &cpus[cpunum()]
extern struct proc *proc asm("%gs:4"); // cpus[cpunum()].proc
It seems the code above is compiled, but not linked in an expected way. I am porting xv6 to Rust, and as a stepping stone I am porting it to Clang 3.8.0 (instead of GCC). But during the build, the linker issued the following error message:
ld -m elf_i386 -T kernel.ld -o kernel entry.o bio.o console.o exec.o file.o fs.o ide.o ioapic.o kalloc.o kbd.o lapic.o log.o main.o mp.o picirq.o pipe.o proc.o sleeplock.o spinlock.o string.o swtch.o syscall.o sysfile.o sysproc.o timer.o trapasm.o trap.o uart.o vectors.o vm.o -b binary initcode entryother
console.o: In function `panic':
.../console.c:114: undefined reference to `%gs:0'