# HG changeset patch # User William Astle # Date 1395467363 21600 # Node ID 6821f485570222f059218910663aa4d0afb7af74 # Parent b30091890d6270d692016992db1cd6d4d671c11f 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. diff -r b30091890d62 -r 6821f4855702 lwlink/link.c --- a/lwlink/link.c Tue Mar 04 23:10:13 2014 -0700 +++ b/lwlink/link.c Fri Mar 21 23:49:23 2014 -0600 @@ -47,10 +47,16 @@ void check_section_name(char *name, int *base, fileinfo_t *fn, int down) { int sn; + sectopt_t *so; + // fprintf(stderr, "Considering sections in %s (%d) for %s\n", fn -> filename, fn -> forced, name); if (fn -> forced == 0) return; + for (so = section_opts; so; so = so -> next) + if (!strcmp(so -> name, name)) + break; + for (sn = 0; sn < fn -> nsections; sn++) { // fprintf(stderr, " Considering section %s\n", fn -> sections[sn].name); @@ -62,7 +68,8 @@ // fprintf(stderr, " Found\n"); sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1)); sectlist[nsects].ptr = &(fn -> sections[sn]); - + + fn -> sections[sn].processed = 1; if (down) { @@ -74,6 +81,14 @@ fn -> sections[sn].loadaddress = *base; *base += fn -> sections[sn].codesize; } + if (down && so && so -> aftersize) + { + sectlist[nsects].ptr -> afterbytes = so -> afterbytes; + sectlist[nsects].ptr -> aftersize = so -> aftersize; + sectlist[nsects].ptr -> loadaddress -= so -> aftersize; + *base -= so -> aftersize; + so -> aftersize = 0; + } nsects++; // fprintf(stderr, "Adding section %s (%s)\n",fn -> sections[sn].name, fn -> filename); }