Mercurial > hg > index.cgi
comparison lwlink/link.c @ 325:6821f4855702
Fix bug with section padding and downward allocation.
When placing sections with the "high" method, padding was added to the
section instance at the lowest address insted of the highest as is
appropriate for the padafter option. Explicitly handle the padding for the
first instance encountered (highest address) when growing down.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 21 Mar 2014 23:49:23 -0600 |
parents | fcd103148aa6 |
children | 221b5f58d8ad |
comparison
equal
deleted
inserted
replaced
324:b30091890d62 | 325:6821f4855702 |
---|---|
45 sectopt_t *section_opts = NULL; | 45 sectopt_t *section_opts = NULL; |
46 | 46 |
47 void check_section_name(char *name, int *base, fileinfo_t *fn, int down) | 47 void check_section_name(char *name, int *base, fileinfo_t *fn, int down) |
48 { | 48 { |
49 int sn; | 49 int sn; |
50 sectopt_t *so; | |
51 | |
50 // fprintf(stderr, "Considering sections in %s (%d) for %s\n", fn -> filename, fn -> forced, name); | 52 // fprintf(stderr, "Considering sections in %s (%d) for %s\n", fn -> filename, fn -> forced, name); |
51 if (fn -> forced == 0) | 53 if (fn -> forced == 0) |
52 return; | 54 return; |
55 | |
56 for (so = section_opts; so; so = so -> next) | |
57 if (!strcmp(so -> name, name)) | |
58 break; | |
53 | 59 |
54 for (sn = 0; sn < fn -> nsections; sn++) | 60 for (sn = 0; sn < fn -> nsections; sn++) |
55 { | 61 { |
56 // fprintf(stderr, " Considering section %s\n", fn -> sections[sn].name); | 62 // fprintf(stderr, " Considering section %s\n", fn -> sections[sn].name); |
57 if (!strcmp(name, (char *)(fn -> sections[sn].name))) | 63 if (!strcmp(name, (char *)(fn -> sections[sn].name))) |
60 continue; | 66 continue; |
61 // we have a match | 67 // we have a match |
62 // fprintf(stderr, " Found\n"); | 68 // fprintf(stderr, " Found\n"); |
63 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1)); | 69 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1)); |
64 sectlist[nsects].ptr = &(fn -> sections[sn]); | 70 sectlist[nsects].ptr = &(fn -> sections[sn]); |
65 | 71 |
72 | |
66 fn -> sections[sn].processed = 1; | 73 fn -> sections[sn].processed = 1; |
67 if (down) | 74 if (down) |
68 { | 75 { |
69 *base -= fn -> sections[sn].codesize; | 76 *base -= fn -> sections[sn].codesize; |
70 fn -> sections[sn].loadaddress = *base; | 77 fn -> sections[sn].loadaddress = *base; |
71 } | 78 } |
72 else | 79 else |
73 { | 80 { |
74 fn -> sections[sn].loadaddress = *base; | 81 fn -> sections[sn].loadaddress = *base; |
75 *base += fn -> sections[sn].codesize; | 82 *base += fn -> sections[sn].codesize; |
83 } | |
84 if (down && so && so -> aftersize) | |
85 { | |
86 sectlist[nsects].ptr -> afterbytes = so -> afterbytes; | |
87 sectlist[nsects].ptr -> aftersize = so -> aftersize; | |
88 sectlist[nsects].ptr -> loadaddress -= so -> aftersize; | |
89 *base -= so -> aftersize; | |
90 so -> aftersize = 0; | |
76 } | 91 } |
77 nsects++; | 92 nsects++; |
78 // fprintf(stderr, "Adding section %s (%s)\n",fn -> sections[sn].name, fn -> filename); | 93 // fprintf(stderr, "Adding section %s (%s)\n",fn -> sections[sn].name, fn -> filename); |
79 } | 94 } |
80 } | 95 } |