History

Add riscv dll support

Most support was already present. riscv64-link.c: - create_plt_entry: - remove DLLs unimplemented! - relocate: - Add TCC_OUTPUT_DLL for R_RISCV_32, R_RISCV_64 tccelf.c: - prepare_dynamic_rel: - Add R_RISCV_32, R_RISCV_64

herman ten brugge committed 6 years ago

Commit a0a0f4d1 parent b8fb2b02 files · +30 −6Browse files

Unified · Split

2 files
  1. riscv64-link.c +25 −5
  2. tccelf.c +5 −1
riscv64-link.c+25−5
@@ -101,9 +101,6 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_ · 100 unmodified lines
101101 uint8_t *p;
102102 unsigned plt_offset;
103103
104− if (s1->output_type == TCC_OUTPUT_DLL)
105− tcc_error("DLLs unimplemented!");
106−
107104 if (plt->data_offset == 0)
108105 section_ptr_add(plt, 32);
109106 plt_offset = plt->data_offset;
@@ -168,7 +165,7 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 58 unmodified lines
168165 {
169166 uint64_t off64;
170167 uint32_t off32;
171− int sym_index = ELFW(R_SYM)(rel->r_info);
168+ int sym_index = ELFW(R_SYM)(rel->r_info), esym_index;
172169 ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
173170
174171 switch(type) {
@@ -284,10 +281,33 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, · 109 unmodified lines
284281 return;
285282
286283 case R_RISCV_32:
284+ if (s1->output_type == TCC_OUTPUT_DLL) {
285+ /* XXX: this logic may depend on TCC's codegen
286+ now TCC uses R_RISCV_RELATIVE even for a 64bit pointer */
287+ qrel->r_offset = rel->r_offset;
288+ qrel->r_info = ELFW(R_INFO)(0, R_RISCV_RELATIVE);
289+ /* Use sign extension! */
290+ qrel->r_addend = (int)read32le(ptr) + val;
291+ qrel++;
292+ }
287293 add32le(ptr, val);
288294 return;
289− case R_RISCV_JUMP_SLOT:
290295 case R_RISCV_64:
296+ if (s1->output_type == TCC_OUTPUT_DLL) {
297+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
298+ qrel->r_offset = rel->r_offset;
299+ if (esym_index) {
300+ qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_64);
301+ qrel->r_addend = rel->r_addend;
302+ qrel++;
303+ break;
304+ } else {
305+ qrel->r_info = ELFW(R_INFO)(0, R_RISCV_RELATIVE);
306+ qrel->r_addend = read64le(ptr) + val;
307+ qrel++;
308+ }
309+ }
310+ case R_RISCV_JUMP_SLOT:
291311 add64le(ptr, val);
292312 return;
293313 case R_RISCV_ADD64:
tccelf.c+5−1
@@ -1029,7 +1029,8 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 1028 unmodified lines
10291029 {
10301030 int count = 0;
10311031 #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) || \
1032− defined(TCC_TARGET_ARM) || defined(TCC_TARGET_ARM64)
1032+ defined(TCC_TARGET_ARM) || defined(TCC_TARGET_ARM64) || \
1033+ defined(TCC_TARGET_RISCV64)
10331034 ElfW_Rel *rel;
10341035 for_each_elem(sr, 0, rel, ElfW_Rel) {
10351036 int sym_index = ELFW(R_SYM)(rel->r_info);
@@ -1052,6 +1053,9 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 16 unmodified lines
10521053 #elif defined(TCC_TARGET_ARM64)
10531054 case R_AARCH64_ABS32:
10541055 case R_AARCH64_ABS64:
1056+#elif defined(TCC_TARGET_RISCV64)
1057+ case R_RISCV_32:
1058+ case R_RISCV_64:
10551059 #endif
10561060 count++;
10571061 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t