Using position independent code without GOT
<p>I am having a problem compiling multiple PIC files without the Global offset table.</p>

<p>When compiling the first file onefile.c with the following parameters the assembly does not include reference to the GOT:</p>

<blockquote>
  <p>arm-none-eabi-gcc.exe first.c -nosdlib -fPIE -march=armv7-a -o first.o</p>
</blockquote>

<p>first.c</p>

<pre><code>void function();
int main();

int main()
{
    void* function_pointer;
    function_pointer = &amp;function;
}

void function()
{

}
</code></pre>

<p>Assembly:</p>

<pre><code>.text:00008000 ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:00008000                 EXPORT main
.text:00008000 main
.text:00008000
.text:00008000 var_8           = -8
.text:00008000 var_s0          =  0
.text:00008000
.text:00008000                 STR             R11, [SP,#-4+var_s0]!
.text:00008004                 ADD             R11, SP, #0
.text:00008008                 SUB             SP, SP, #0xC
.text:0000800C                 LDR             R3, =(function - 0x8018)
.text:00008010                 ADD             R3, PC, R3 ; function
.text:00008014                 STR             R3, [R11,#var_8]
.text:00008018                 MOV             R3, #0
.text:0000801C                 MOV             R0, R3
.text:00008020                 SUB             SP, R11, #0
.text:00008024                 LDR             R11, [SP+var_s0],#4
.text:00008028                 BX              LR
.text:00008028 ; End of function main
</code></pre>

<p>Notice how in address 0x8010 the register R3 has the address of the function "function" without using the GOT.</p>

<p>But when splitting the file to multiple .c and .h files the result is changing</p>

<blockquote>
  <p>arm-none-eabi-gcc.exe twofiles1.c twofiles2.c -nostdlib -fPIE
  -march=armv7-a -o twofiles.o</p>
</blockquote>

<p>twofiles1.c:</p>

<pre><code>#include "twofiles1.h"

int main()
{
    void* function_pointer;
    function_pointer = &amp;function;
}
</code></pre>

<p>twofiles1.h:</p>

<pre><code>#include "twofiles2.h"

int main();
</code></pre>

<p>twofiles2.c:</p>

<pre><code>void function()
{

}
</code></pre>

<p>twofiles2.h:</p>

<pre><code>void function();
</code></pre>

<p>assembly:</p>

<pre><code>.text:00008000 ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:00008000                 EXPORT main
.text:00008000 main
.text:00008000
.text:00008000 var_8           = -8
.text:00008000 var_s0          =  0
.text:00008000
.text:00008000                 STR             R11, [SP,#-4+var_s0]!
.text:00008004                 ADD             R11, SP, #0
.text:00008008                 SUB             SP, SP, #0xC
.text:0000800C                 LDR             R2, =(_GLOBAL_OFFSET_TABLE_ - 0x8018)
.text:00008010                 ADD             R2, PC, R2 ; _GLOBAL_OFFSET_TABLE_
.text:00008014                 LDR             R3, =(function_ptr - 0x18054)
.text:00008018                 LDR             R3, [R2,R3] ; function
.text:0000801C                 STR             R3, [R11,#var_8]
.text:00008020                 MOV             R3, #0
.text:00008024                 MOV             R0, R3
.text:00008028                 SUB             SP, R11, #0
.text:0000802C                 LDR             R11, [SP+var_s0],#4
.text:00008030                 BX              LR
.text:00008030 ; End of function main
</code></pre>

<p>Notice how the address of the function "function" is calculated <strong>with</strong> the GOT. That is what I would like to refrain from
Is there any solution of achieving the same assembly as the first result?</p>