title: Object file to binary code
body: <p>Let's suppose I have a C file with  no external dependency, and only const data section. I would like to compile this file, and then get a binary blob I can load in another program, where the function would be used through a function pointer.</p>
  
  <p>Let's take an example, here is a fictionnal binary module, f1.c</p>
  
  <pre><code>static const unsigned char mylut[256] = {
      [0 ... 127] = 0,
      [128 ... 255] = 1,
  };
  
  void f1(unsigned char * src, unsigned char * dst, int len)
  {
      while(len) {
          *dst++ = mylut[*src++];
          len--;
      }
  }
  </code></pre>
  
  <p>I would like to compile it to f1.o, then f1.bin, and use it like this
  in prog.c</p>
  
  <pre><code>int somefunc() {
      unsigned char  * codedata;
      f1_type_ptr  f1_ptr;
      /* open f1.bin, and read it into codedata */
  
      /* set function pointer to beginning of loaded data */
      f1_ptr =(f1_type_ptr)codedata;
  
      /* call !*/
      f1_ptr(src, dst, len);
  }
  </code></pre>
  
  <p>I suppose going from f1.c to f1.o involves -fPIC to get position independance. What are the flags or linker script that I can use
  to go from f1.o to f1.bin ?</p>
  
  <p>Clarification :</p>
  
  <p>I know about dynamic linking. dynamic linking is not possible in this case. The linking step has to be <em>cast func pointer to loaded data</em>, if it is possible.</p>
  
  <p>Please assume there is no OS support. If I could, I would for example
  write f1 in assembly with PC related adressing. </p>