Skip to content

Commit

Permalink
Added machine-readable map file output (via -N)
Browse files Browse the repository at this point in the history
  • Loading branch information
deplinenoise committed Dec 6, 2011
1 parent d2cf4c5 commit 1aad086
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int main(int argc,char *argv[])
bool stdlib = TRUE;
int so_version = 0; /* minum version for shared objects */
uint16_t flags = 0; /* input file flags */
int enable_newstyle_mapfile = 0;

/* initialize and set default values */
memset(gv,0,sizeof(struct GlobalVars));
Expand Down Expand Up @@ -500,6 +501,10 @@ int main(int argc,char *argv[])
gv->map_file = stdout;
break;

case 'N': /* machine-readable map output */
enable_newstyle_mapfile = 1;
break;

case 'P': /* protect symbol against stripping */
if (buf = get_option_arg(argc,argv,&i))
add_symnames(&gv->prot_syms,buf);
Expand Down Expand Up @@ -577,6 +582,15 @@ int main(int argc,char *argv[])
sizeof(char **), flavours_cmp);
}

/* if map file is enabled, write to <output>.map */
if (enable_newstyle_mapfile) {
char map_path[260];
snprintf(map_path, sizeof map_path, "%s.map", gv->dest_name);
map_path[sizeof(map_path)-1] = '\0';
if (NULL == (gv->map_file_newstyle = fopen(map_path, "w")))
fprintf(stderr, "warning: couldn't create '%s'\n", map_path);
}

/* link them... */
linker_init(gv);
linker_load(gv); /* load all objects and libraries and their symbols */
Expand All @@ -590,6 +604,11 @@ int main(int argc,char *argv[])
linker_write(gv); /* write output file in selected target format */
linker_cleanup(gv);

if (gv->map_file_newstyle) {
fclose(gv->map_file_newstyle);
gv->map_file_newstyle = NULL;
}

cleanup(gv);
return 0;
}
15 changes: 15 additions & 0 deletions t_amigahunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ static void writeexec(struct GlobalVars *gv,FILE *f)
{
struct LinkedSection *ls = (struct LinkedSection *)gv->lnksec.first;
struct LinkedSection *nextls;
FILE *hunk_map = gv->map_file_newstyle;
int i=0;

fwrite32be(f,HUNK_HEADER);
Expand Down Expand Up @@ -1721,23 +1722,37 @@ static void writeexec(struct GlobalVars *gv,FILE *f)
/* section loop */
ls = (struct LinkedSection *)gv->lnksec.first;
while (nextls = (struct LinkedSection *)ls->n.next) {
const char *hunk_typename = "";
exthunk = symhunk = FALSE;

switch (ls->type) { /* section type */
case ST_CODE:
fwrite32be(f,HUNK_CODE);
hunk_typename = "CODE";
break;
case ST_DATA:
fwrite32be(f,HUNK_DATA);
hunk_typename = "DATA";
break;
case ST_UDATA:
fwrite32be(f,HUNK_BSS);
hunk_typename = "BSS";
break;
default:
ierror("writeexec(): Illegal section type %u",ls->type);
break;
}

if (hunk_map) {
uint32_t offset = 0;
struct Symbol *sym = (struct Symbol *)ls->symbols.first;
fprintf(hunk_map, "SECTION size=%d type=HUNK_%s\n", (uint32_t) ((ls->size+3) & ~3), hunk_typename);
while (sym->n.next) {
fprintf(hunk_map, " %s %d\n", sym->name, (uint32_t) sym->value);
sym = (struct Symbol*) sym->n.next;
}
}

fix_reloc_addends(gv,ls);
if (ls->flags & SF_UNINITIALIZED) {
fwrite32be(f,(ls->size+3)>>2); /* bss - size only */
Expand Down
1 change: 1 addition & 0 deletions version.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void show_usage(void)
"-sd merge all data and bss sections\n"
"-t trace file accesses by the linker\n"
"-M print segment mappings and symbol values\n"
"-N generate machine-readable map data (.map)\n"
"-n no page alignment\n"
"-q keep relocations in the final executable\n"
"-r generate relocatable object\n"
Expand Down
1 change: 1 addition & 0 deletions vlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ struct GlobalVars {
bool textbaserel; /* allow base-relative access on code secs. */
uint8_t min_alignment; /* minimal section alignment (default 0) */
FILE *map_file; /* map file */
FILE *map_file_newstyle; /* map file, new style */
FILE *trace_file; /* linker trace output */
struct SymNames **trace_syms; /* trace-symbol hash table */
struct SymNames *prot_syms; /* list of protected symbols */
Expand Down

0 comments on commit 1aad086

Please sign in to comment.