commit 29dc92ca622fc1a51d03db61131eed586fa370ab
parent c658360817ac84cd259dbff0ea836dac8b647ad1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 21 Mar 2024 08:04:05 +0100
as: Add symbols for every section
It is usually a good idea to have a symbol for every section because
relocations can reference them and because the code can use them
in some special cases.
Diffstat:
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c
@@ -50,6 +50,7 @@ static struct lsymbol *hashtbl[HASHSIZ], *symlast, *symlist;
static Symbol *cursym;
static Alloc *tmpalloc;
+static int secindex, symindex;
#ifndef NDEBUG
void
@@ -280,9 +281,8 @@ newsec(Symbol *sym, char *attr)
Section *sec;
struct lsection *lsec;
struct lsymbol *lsym;
- static unsigned index;
- if (index == UINT_MAX) {
+ if (secindex == INT_MAX) {
fputs("as: too many sections\n", stderr);
exit(EXIT_FAILURE);
}
@@ -299,10 +299,12 @@ newsec(Symbol *sym, char *attr)
sec->flags = 0;
sec->fill = 0;
sec->align = 0;
- sec->index = index++;
+ sec->index = secindex;
sec->flags |= secflags(attr);
sec->type = sectype(sec->flags);
+ sym->type = sec->type;
+ sym->index = symindex;
lsym = (struct lsymbol *) sym;
lsym->sec = sec;
@@ -313,13 +315,23 @@ newsec(Symbol *sym, char *attr)
exit(EXIT_FAILURE);
}
- if (!setsec(obj, &sec->index, sec)) {
+ if (!setsec(obj, &secindex, sec)) {
fprintf(stderr,
"as: error adding section '%s' to output\n",
sym->name);
exit(EXIT_FAILURE);
}
+ if (!setsym(obj, &symindex, sym)) {
+ fprintf(stderr,
+ "as: error adding section symbol '%s' to output\n",
+ sym->name);
+ exit(EXIT_FAILURE);
+ }
+
+ secindex++;
+ symindex++;
+
return sec;
}