tcc: re-enable correct option -r support
[tinycc.git] / c67-link.c
blobce452691b7ad3e8baae360beea35f066e96cc85a
1 #ifdef TARGET_DEFS_ONLY
3 #define EM_TCC_TARGET EM_C60
5 /* relocation type for 32 bit data relocation */
6 #define R_DATA_32 R_C60_32
7 #define R_DATA_PTR R_C60_32
8 #define R_JMP_SLOT R_C60_JMP_SLOT
9 #define R_GLOB_DAT R_C60_GLOB_DAT
10 #define R_COPY R_C60_COPY
12 #define R_NUM R_C60_NUM
14 #define ELF_START_ADDR 0x00000400
15 #define ELF_PAGE_SIZE 0x1000
17 #define PCRELATIVE_DLLPLT 0
18 #define RELOCATE_DLLPLT 0
20 #else /* !TARGET_DEFS_ONLY */
22 #include "tcc.h"
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)
28 switch (reloc_type) {
29 case R_C60_32:
30 case R_C60LO16:
31 case R_C60HI16:
32 case R_C60_GOT32:
33 case R_C60_GOTOFF:
34 case R_C60_GOTPC:
35 case R_C60_COPY:
36 return 0;
38 case R_C60_PLT32:
39 return 1;
42 tcc_error ("Unknown relocation type: %d", reloc_type);
43 return -1;
46 /* Returns an enumerator to describe wether and when the relocation needs a
47 GOT and/or PLT entry to be created. See tcc.h for a description of the
48 different values. */
49 int gotplt_entry_type (int reloc_type)
51 switch (reloc_type) {
52 case R_C60_32:
53 case R_C60LO16:
54 case R_C60HI16:
55 case R_C60_COPY:
56 return NO_GOTPLT_ENTRY;
58 case R_C60_GOTOFF:
59 case R_C60_GOTPC:
60 return BUILD_GOT_ONLY;
62 case R_C60_PLT32:
63 case R_C60_GOT32:
64 return ALWAYS_GOTPLT_ENTRY;
67 tcc_error ("Unknown relocation type: %d", reloc_type);
68 return -1;
71 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
73 tcc_error("C67 got not implemented");
74 return 0;
77 /* relocate the PLT: compute addresses and offsets in the PLT now that final
78 address for PLT and GOT are known (see fill_program_header) */
79 ST_FUNC void relocate_plt(TCCState *s1)
81 uint8_t *p, *p_end;
83 if (!s1->plt)
84 return;
86 p = s1->plt->data;
87 p_end = p + s1->plt->data_offset;
89 if (p < p_end) {
90 /* XXX: TODO */
91 while (p < p_end) {
92 /* XXX: TODO */
97 void relocate_init(Section *sr) {}
99 void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
101 switch(type) {
102 case R_C60_32:
103 *(int *)ptr += val;
104 break;
105 case R_C60LO16:
107 uint32_t orig;
109 /* put the low 16 bits of the absolute address add to what is
110 already there */
111 orig = ((*(int *)(ptr )) >> 7) & 0xffff;
112 orig |= (((*(int *)(ptr+4)) >> 7) & 0xffff) << 16;
114 /* patch both at once - assumes always in pairs Low - High */
115 *(int *) ptr = (*(int *) ptr & (~(0xffff << 7)) ) |
116 (((val+orig) & 0xffff) << 7);
117 *(int *)(ptr+4) = (*(int *)(ptr+4) & (~(0xffff << 7)) ) |
118 ((((val+orig)>>16) & 0xffff) << 7);
120 break;
121 case R_C60HI16:
122 break;
123 default:
124 fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
125 type, (unsigned) addr, ptr, (unsigned) val);
126 break;
130 #endif /* !TARGET_DEFS_ONLY */