2 #define HAVE_SECTION_RELOC
4 static ElfW_Rel
*qrel
; /* ptr to next reloc entry reused */
5 ST_DATA
struct reloc_info relocs_info
[] = {
6 INIT_RELOC_INFO (R_386_32
, 0, NO_GOTPLT_ENTRY
, 0)
7 INIT_RELOC_INFO (R_386_PC32
, 1, AUTO_GOTPLT_ENTRY
, 0)
8 INIT_RELOC_INFO (R_386_PLT32
, 1, ALWAYS_GOTPLT_ENTRY
, 0)
9 INIT_RELOC_INFO (R_386_GLOB_DAT
, 0, NO_GOTPLT_ENTRY
, 0)
10 INIT_RELOC_INFO (R_386_JMP_SLOT
, 1, NO_GOTPLT_ENTRY
, 0)
11 INIT_RELOC_INFO (R_386_GOTPC
, 0, BUILD_GOT_ONLY
, 0)
12 INIT_RELOC_INFO (R_386_GOTOFF
, 0, BUILD_GOT_ONLY
, 0)
13 INIT_RELOC_INFO (R_386_GOT32
, 0, ALWAYS_GOTPLT_ENTRY
, 0)
14 INIT_RELOC_INFO (R_386_GOT32X
, 0, ALWAYS_GOTPLT_ENTRY
, 0)
15 INIT_RELOC_INFO (R_386_16
, 0, NO_GOTPLT_ENTRY
, 0)
16 INIT_RELOC_INFO (R_386_PC16
, 1, AUTO_GOTPLT_ENTRY
, 0)
19 void relocate_init(Section
*sr
)
21 qrel
= (ElfW_Rel
*) sr
->data
;
24 void relocate(TCCState
*s1
, ElfW_Rel
*rel
, int type
, char *ptr
, addr_t addr
, addr_t val
)
26 int sym_index
, esym_index
;
28 sym_index
= ELFW(R_SYM
)(rel
->r_info
);
32 if (s1
->output_type
== TCC_OUTPUT_DLL
) {
33 esym_index
= s1
->symtab_to_dynsym
[sym_index
];
34 qrel
->r_offset
= rel
->r_offset
;
36 qrel
->r_info
= ELFW(R_INFO
)(esym_index
, R_386_32
);
40 qrel
->r_info
= ELFW(R_INFO
)(0, R_386_RELATIVE
);
47 if (s1
->output_type
== TCC_OUTPUT_DLL
) {
49 esym_index
= s1
->symtab_to_dynsym
[sym_index
];
51 qrel
->r_offset
= rel
->r_offset
;
52 qrel
->r_info
= ELFW(R_INFO
)(esym_index
, R_386_PC32
);
57 add32le(ptr
, val
- addr
);
60 add32le(ptr
, val
- addr
);
67 add32le(ptr
, s1
->got
->sh_addr
- addr
);
70 add32le(ptr
, val
- s1
->got
->sh_addr
);
74 /* we load the got offset */
75 add32le(ptr
, s1
->sym_attrs
[sym_index
].got_offset
);
78 if (s1
->output_format
!= TCC_OUTPUT_FORMAT_BINARY
) {
80 tcc_error("can only produce 16-bit binary files");
82 write16le(ptr
, read16le(ptr
) + val
);
85 if (s1
->output_format
!= TCC_OUTPUT_FORMAT_BINARY
)
87 write16le(ptr
, read16le(ptr
) + val
- addr
);
93 /* This reloction must copy initialized data from the library
94 to the program .bss segment. Currently made like for ARM
95 (to remove noise of defaukt case). Is this true?
99 fprintf(stderr
,"FIXME: handle reloc type %d at %x [%p] to %x\n",
100 type
, (unsigned)addr
, ptr
, (unsigned)val
);