How can I create an immovable character with the last (with PIC enabled) gcc? I basically want to have the following C version of the NULL program:
#include <stdio.h>
extern int mem_;
int main(void) {
printf("%p\n", &mem_);
return 0;
}
What I tried is a small assembler file:
.data
.globl mem_
.type mem_,@object
.set mem_, 0
but this creates a roaming character that does not have a value of 0 at runtime.
Background: I'm trying to run an old program that uses this trick to directly access (allocated) Fortran memory as an array. Since the program has "10⁵ LOC", it would be impossible to rewrite everything.
[edit] The GNU Assembler Guide documents the "absolute section" as
. 0 "" 0. , , ld . , "": .
, , , (?), . .struct
" " ; :
.globl mem_
.struct 0
mem_:
*ABS*
objdump
:
$ objdump -t memc
memc: file format elf64-x86-64
[...]
0000000000000540 g F .text 000000000000002b _start
0000000000201030 g .bss 0000000000000000 __bss_start
000000000000064a g F .text 000000000000003c main
0000000000000000 g *ABS* 0000000000000000 mem_
[...]
.