Ld data file makes data size a * ABS * rather than integer

I have a C ++ program that includes an external dependency on an empty xlsx file. To remove this dependency, I converted this file to a binary object to link it directly using:

ld -r -b binary -o template.o template.xlsx

followed by

objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents template.o template.o

Using objdump, I see three declared variables:

$ objdump -x template.o

template.o:     file format elf64-x86-64
template.o
architecture: i386:x86-64, flags 0x00000010:
HAS_SYMS
start address 0x0000000000000000

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .rodata       00000fd1  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
SYMBOL TABLE:
0000000000000000 l    d  .rodata        0000000000000000 .rodata
0000000000000fd1 g       *ABS*  0000000000000000 _binary_template_xlsx_size
0000000000000000 g       .rodata        0000000000000000 _binary_template_xlsx_start
0000000000000fd1 g       .rodata        0000000000000000 _binary_template_xlsx_end

Then I will talk about my program about this data:

template.h:
#ifndef TEMPLATE_H
#define TEMPLATE_H

#include <cstddef>
extern "C" {
  extern const char _binary_template_xlsx_start[];
  extern const char _binary_template_xlsx_end[];
  extern const int  _binary_template_xlsx_size;
}
#endif

This compiles and links well, (although I have some issues with cmake automation, see here: compile and add an object file from a binary using cmake )

, _binary_template_xlsx_size , , . , , (int)&_binary_template_xlsx_size ( (int)(_binary_template_xlsx_end - _binary_template_xlsx_start))

, *ABS* objdump " ", . ++ ( c), int, ?

+5
1

*ABS* - ; --defsym foo=0x1234 ld.

--defsym symbol=expression

,    , . [...]

, C ; C , .

, ( ) , const char [], :

  extern const char _binary_template_xlsx_size[];

, int, :

  extern const char _abs_binary_template_xlsx_size[] asm("_binary_template_xlsx_size");
  #define _binary_template_xlsx_size ((int) (intptr_t) _abs_binary_template_xlsx_size)
+3

All Articles