Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 76 lines (64 sloc) 1.757 kB
71175bd @deplinenoise Checking in vasm snapshot.
deplinenoise authored
1 /* reloc.c - relocation support functions */
2 /* (c) in 2010 by Volker Barthelmann and Frank Wille */
3
4 #include "vasm.h"
5
6
7 nreloc *new_nreloc(void)
8 {
9 nreloc *new = mymalloc(sizeof(*new));
10 new->mask = -1;
11 new->offset = 0;
12 new->size = 0;
13 new->addend = 0;
14 return new;
15 }
16
17
18 rlist *add_reloc(rlist **relocs,symbol *sym,taddr addend,
19 int type,int size,int offs)
20 {
21 nreloc *r = new_nreloc();
22 rlist *rl = mymalloc(sizeof(rlist));
23
24 r->size = size;
25 r->offset = offs;
26 r->sym = sym;
27 r->addend = addend;
28 rl->type = type;
29 rl->reloc = r;
30 rl->next = *relocs;
31 *relocs = rl;
32 return rl;
33 }
34
35
36 void do_pic_check(rlist *r)
37 /* generate an error on a non-PC-relative relocation */
38 {
39 int t;
40
41 while (r) {
42 t = r->type;
43 if (t==REL_ABS || t==REL_UABS)
44 general_error(34); /* relocation not allowed */
45 r = r->next;
46 }
47 }
48
49 void print_reloc(FILE *f,int type,nreloc *p)
50 {
51 if (type<=LAST_STANDARD_RELOC){
52 static const char *rname[] = {
53 "none","abs","pc","got","gotrel","gotoff","globdat","plt","pltrel",
54 "pltoff","sd","uabs","localpc","loadrel","copy","jmpslot","secoff"
55 };
56 fprintf(f,"r%s(%d,%d,0x%llx,0x%llx,",rname[type],p->offset,p->size,
57 ((unsigned long long)p->mask)&taddrmask,
58 ((unsigned long long)p->addend)&taddrmask);
59 }
60 #ifdef VASM_CPU_PPC
61 else if (type<=LAST_PPC_RELOC){
62 static const char *rname[] = {
63 "sd2","sd21","sdi16","drel","brel"
64 };
65 fprintf(f,"r%s(%d,%d,0x%llx,0x%llx,",rname[type-(LAST_STANDARD_RELOC+1)],
66 p->offset,p->size,((unsigned long long)p->mask)&taddrmask,
67 ((unsigned long long)p->addend)&taddrmask);
68 }
69 #endif
70 else
71 fprintf(f,"unknown reloc(");
72
73 print_symbol(f,p->sym);
74 fprintf(f,") ");
75 }
Something went wrong with that request. Please try again.