1 #ifdef TARGET_DEFS_ONLY
3 #define EM_TCC_TARGET EM_386
5 /* relocation type for 32 bit data relocation */
6 #define R_DATA_32 R_386_32
7 #define R_DATA_PTR R_386_32
8 #define R_JMP_SLOT R_386_JMP_SLOT
9 #define R_GLOB_DAT R_386_GLOB_DAT
10 #define R_COPY R_386_COPY
12 #define R_NUM R_386_NUM
14 #define ELF_START_ADDR 0x08048000
15 #define ELF_PAGE_SIZE 0x1000
17 #define HAVE_SECTION_RELOC
18 #define PCRELATIVE_DLLPLT 0
20 #else /* !TARGET_DEFS_ONLY */
24 /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
25 relocations, returns -1. */
26 int code_reloc (int reloc_type
)
46 tcc_error ("Unknown relocation type: %d", reloc_type
);
50 /* Returns an enumerator to describe wether and when the relocation needs a
51 GOT and/or PLT entry to be created. See tcc.h for a description of the
53 int gotplt_entry_type (int reloc_type
)
61 return NO_GOTPLT_ENTRY
;
65 return AUTO_GOTPLT_ENTRY
;
69 return BUILD_GOT_ONLY
;
74 return ALWAYS_GOTPLT_ENTRY
;
77 tcc_error ("Unknown relocation type: %d", reloc_type
);
81 static ElfW_Rel
*qrel
; /* ptr to next reloc entry reused */
83 void relocate_init(Section
*sr
)
85 qrel
= (ElfW_Rel
*) sr
->data
;
88 void relocate(TCCState
*s1
, ElfW_Rel
*rel
, int type
, char *ptr
, addr_t addr
, addr_t val
)
90 int sym_index
, esym_index
;
92 sym_index
= ELFW(R_SYM
)(rel
->r_info
);
96 if (s1
->output_type
== TCC_OUTPUT_DLL
) {
97 esym_index
= s1
->symtab_to_dynsym
[sym_index
];
98 qrel
->r_offset
= rel
->r_offset
;
100 qrel
->r_info
= ELFW(R_INFO
)(esym_index
, R_386_32
);
104 qrel
->r_info
= ELFW(R_INFO
)(0, R_386_RELATIVE
);
111 if (s1
->output_type
== TCC_OUTPUT_DLL
) {
113 esym_index
= s1
->symtab_to_dynsym
[sym_index
];
115 qrel
->r_offset
= rel
->r_offset
;
116 qrel
->r_info
= ELFW(R_INFO
)(esym_index
, R_386_PC32
);
121 add32le(ptr
, val
- addr
);
124 add32le(ptr
, val
- addr
);
131 add32le(ptr
, s1
->got
->sh_addr
- addr
);
134 add32le(ptr
, val
- s1
->got
->sh_addr
);
138 /* we load the got offset */
139 add32le(ptr
, s1
->sym_attrs
[sym_index
].got_offset
);
142 if (s1
->output_format
!= TCC_OUTPUT_FORMAT_BINARY
) {
144 tcc_error("can only produce 16-bit binary files");
146 write16le(ptr
, read16le(ptr
) + val
);
149 if (s1
->output_format
!= TCC_OUTPUT_FORMAT_BINARY
)
151 write16le(ptr
, read16le(ptr
) + val
- addr
);
157 /* This reloction must copy initialized data from the library
158 to the program .bss segment. Currently made like for ARM
159 (to remove noise of defaukt case). Is this true?
163 fprintf(stderr
,"FIXME: handle reloc type %d at %x [%p] to %x\n",
164 type
, (unsigned)addr
, ptr
, (unsigned)val
);
169 #endif /* !TARGET_DEFS_ONLY */