From 88e560b915dc753c85898e35af1e0a751a4cf723 Mon Sep 17 00:00:00 2001 From: jesusc Date: Wed, 30 Jul 2003 05:32:48 +0000 Subject: [PATCH] Linker complaints if linked modules have conflicting options. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2784 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 26 ++++++++++++++++++++++++++ as/mcs51/asdata.c | 2 ++ as/mcs51/aslink.h | 4 ++++ as/mcs51/asm.h | 5 ++++- as/mcs51/asmain.c | 14 ++++++++++++++ as/mcs51/asout.c | 5 +++++ as/mcs51/i51pst.c | 3 ++- as/mcs51/lkdata.c | 5 +++++ as/mcs51/lklibr.c | 8 ++++---- as/mcs51/lkmain.c | 26 ++++++++++++++++++++++++++ as/z80/asdata.c | 2 ++ as/z80/asm.h | 3 +++ as/z80/asmain.c | 13 +++++++++++++ as/z80/asout.c | 5 +++++ as/z80/z80pst.c | 1 + link/z80/aslink.h | 4 ++++ link/z80/lkdata.c | 5 +++++ link/z80/lklibr.c | 6 +++--- link/z80/lkmain.c | 26 ++++++++++++++++++++++++++ src/SDCCglue.c | 27 +++++++++++++++++++++++++++ 20 files changed, 181 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index d854ebd6..dbcda524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +2003-07-29 Jesus Calvino-Fraga + + Linker now complaints if linked modules have conflicting options, for + example, one compiled using --model-large and another one compiled with + --model-small. The following files were modified: + + * as\mcs51\asdata.c + * as\mcs51\aslink.h + * as\mcs51\asm.h + * as\mcs51\asmain.c + * as\mcs51\asout.c + * as\mcs51\i51pst.c + * as\mcs51\lkdata.c + * as\mcs51\lklibr.c + * as\mcs51\lkmain.c + * as\z80\asdata.c + * as\z80\asm.h + * as\z80\asmain.c + * as\z80\asout.c + * as\z80\z80pst.c + * link\z80\aslink.h + * link\z80\lkdata.c + * link\z80\lklibr.c + * link\z80\lkmain.c + * src\SDCCglue.c + 2003-07-28 Jesus Calvino-Fraga *link/z80/aslink.h, link/z80/lklibr.c, as/mcs51/aslink.h, diff --git a/as/mcs51/asdata.c b/as/mcs51/asdata.c index 07c065ce..c6ed0b44 100644 --- a/as/mcs51/asdata.c +++ b/as/mcs51/asdata.c @@ -129,6 +129,8 @@ char tb[NTITL]; /* Title string buffer */ char stb[NSBTL]; /* Subtitle string buffer */ +char optsdcc[NINPUT]; /* sdcc compile options + */ int flat24Mode; /* non-zero if we are using DS390 24 bit * flat mode (via .flat24 directive). */ diff --git a/as/mcs51/aslink.h b/as/mcs51/aslink.h index fa4f1d1f..263467a0 100644 --- a/as/mcs51/aslink.h +++ b/as/mcs51/aslink.h @@ -459,6 +459,10 @@ extern unsigned char ctype[]; /* array of character types, one per * ASCII character */ +extern char sdccopt[NINPUT]; +extern char sdccopt_module[NINPUT]; +extern char curr_module[NINPUT]; + /* * Character Type Definitions */ diff --git a/as/mcs51/asm.h b/as/mcs51/asm.h index 0036a063..aa33d254 100644 --- a/as/mcs51/asm.h +++ b/as/mcs51/asm.h @@ -327,7 +327,8 @@ struct sym #define S_ORG 24 /* .org */ #define S_MODUL 25 /* .module */ #define S_ASCIS 26 /* .ascis */ -#define S_FLAT24 27 /* .flat24 */ +#define S_FLAT24 27 /* .flat24 */ +#define S_OPTSDCC 28 /* .optsdcc */ /* @@ -478,6 +479,8 @@ extern char tb[NTITL]; /* Title string buffer */ extern char stb[NSBTL]; /* Subtitle string buffer */ +extern char optsdcc[NINPUT]; /* sdcc compile options + */ extern int flat24Mode; /* non-zero if we are using DS390 24 bit * flat mode (via .flat24 directive). */ diff --git a/as/mcs51/asmain.c b/as/mcs51/asmain.c index eed56eac..05689f92 100644 --- a/as/mcs51/asmain.c +++ b/as/mcs51/asmain.c @@ -811,6 +811,20 @@ loop: lmode = SLIST; break; + case S_OPTSDCC: + p = optsdcc; + if ((c = getnb()) != 0) { + do { + if (p < &tb[NINPUT-1]) + *p++ = c; + } while ((c = get()) != 0); + } + *p = 0; + unget(c); + lmode = SLIST; + /*if (pass == 0) printf("optsdcc=%s\n", optsdcc);*/ + break; + case S_GLOBL: do { getid(id, -1); diff --git a/as/mcs51/asout.c b/as/mcs51/asout.c index 8c8362f6..363a2c12 100644 --- a/as/mcs51/asout.c +++ b/as/mcs51/asout.c @@ -925,6 +925,11 @@ outgsd() putc('\n', ofp); } + /* + * Sdcc compile options + */ + if (strlen(optsdcc)) fprintf(ofp, "O %s\n", optsdcc); + /* * Global references and absolutes. */ diff --git a/as/mcs51/i51pst.c b/as/mcs51/i51pst.c index 1e10d954..16c40834 100644 --- a/as/mcs51/i51pst.c +++ b/as/mcs51/i51pst.c @@ -59,7 +59,8 @@ struct mne mne[] = { { NULL, ".org", S_ORG, 0, 0}, { NULL, ".module", S_MODUL, 0, 0}, { NULL, ".ascis", S_ASCIS, 0, 0}, - { NULL, ".flat24", S_FLAT24, 0, 0}, + { NULL, ".flat24", S_FLAT24, 0, 0}, + { NULL, ".optsdcc", S_OPTSDCC, 0, 0}, /* 8051 */ diff --git a/as/mcs51/lkdata.c b/as/mcs51/lkdata.c index 1d100f8a..d6a35175 100644 --- a/as/mcs51/lkdata.c +++ b/as/mcs51/lkdata.c @@ -42,6 +42,11 @@ char *rp; /* pointer into the LST file char rb[NINPUT]; /* LST file text line being * address relocated */ + +char sdccopt[NINPUT]=""; +char sdccopt_module[NINPUT]=""; +char curr_module[NINPUT]=""; + int dflag; /* Debug information output flag */ int oflag; /* Output file type flag diff --git a/as/mcs51/lklibr.c b/as/mcs51/lklibr.c index d7d9cb24..8ca45048 100644 --- a/as/mcs51/lklibr.c +++ b/as/mcs51/lklibr.c @@ -128,16 +128,16 @@ addlib() if (lbphead == NULL) { - foundcount+=addfile(NULL,ip); + foundcount=addfile(NULL, ip); } else { for (lbph=lbphead; lbph; lbph=lbph->next) { - foundcount+=addfile(lbph->path,ip); + foundcount+=addfile(lbph->path, ip); } } - if(foundcount==0) + if(foundcount == 0) { printf("?ASlink-Warning-Couldn't find library '%s'\n", ip); } @@ -238,7 +238,7 @@ int addfile(char * path, char * libfil) if(path==NULL) { - /*'path' can not be null since it is needed to find the '.o' files associated with + /*'path' can not be null since it is needed to find the '.rel' files associated with the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'. That way putting 'path' and 'libfil' together will result into the original filepath as contained in 'str'.*/ diff --git a/as/mcs51/lkmain.c b/as/mcs51/lkmain.c index 842bcb33..548a44fd 100644 --- a/as/mcs51/lkmain.c +++ b/as/mcs51/lkmain.c @@ -465,6 +465,29 @@ link_main() if ((c=endline()) == 0) { return; } switch (c) { + case 'O': /*For some important sdcc options*/ + if (pass == 0) + { + if(strlen(sdccopt)==0) + { + strcpy(sdccopt, &ip[1]); + strcpy(sdccopt_module, curr_module); + } + else + { + if(strcmp(sdccopt, &ip[1])!=0) + { + fprintf(stderr, + "?ASlink-Warning-Conflicting sdcc options:\n" + " \"%s\" in module \"%s\" and\n" + " \"%s\" in module \"%s\".\n", + sdccopt, sdccopt_module, &ip[1], curr_module); + lkerr++; + } + } + } + break; + case 'X': radix = 16; break; @@ -494,7 +517,10 @@ link_main() case 'M': if (pass == 0) + { + strcpy(curr_module, &ip[1]); module(); + } break; case 'A': diff --git a/as/z80/asdata.c b/as/z80/asdata.c index 189be0b2..26b621e2 100644 --- a/as/z80/asdata.c +++ b/as/z80/asdata.c @@ -121,6 +121,8 @@ char tb[NTITL]; /* Title string buffer */ char stb[NSBTL]; /* Subtitle string buffer */ +char optsdcc[NINPUT]; /* sdcc compile options + */ char symtbl[] = { "Symbol Table" }; char aretbl[] = { "Area Table" }; diff --git a/as/z80/asm.h b/as/z80/asm.h index 57e68e78..48e0500f 100644 --- a/as/z80/asm.h +++ b/as/z80/asm.h @@ -272,6 +272,7 @@ struct sym #ifdef SDK # define S_FLOAT 27 /* .df */ #endif +#define S_OPTSDCC 28 /* .optsdcc */ /* * The tsym structure is a linked list of temporary @@ -413,6 +414,8 @@ extern char tb[NTITL]; /* Title string buffer */ extern char stb[NSBTL]; /* Subtitle string buffer */ +extern char optsdcc[NINPUT]; /* sdcc compile options + */ extern char symtbl[]; /* string "Symbol Table" */ extern char aretbl[]; /* string "Area Table" diff --git a/as/z80/asmain.c b/as/z80/asmain.c index 976248a3..f916e9ef 100644 --- a/as/z80/asmain.c +++ b/as/z80/asmain.c @@ -850,6 +850,19 @@ loop: lmode = SLIST; break; + case S_OPTSDCC: + p = optsdcc; + if ((c = getnb()) != 0) { + do { + if (p < &tb[NINPUT-1]) + *p++ = c; + } while ((c = get()) != 0); + } + *p = 0; + unget(c); + lmode = SLIST; + break; + case S_GLOBL: do { getid(id, -1); diff --git a/as/z80/asout.c b/as/z80/asout.c index 5396de3e..c4b3434f 100644 --- a/as/z80/asout.c +++ b/as/z80/asout.c @@ -720,6 +720,11 @@ outgsd() putc('\n', ofp); } + /* + * Sdcc compile options + */ + if (strlen(optsdcc)) fprintf(ofp, "O %s\n", optsdcc); + /* * Global references and absolutes. */ diff --git a/as/z80/z80pst.c b/as/z80/z80pst.c index 7e6dc807..74044865 100644 --- a/as/z80/z80pst.c +++ b/as/z80/z80pst.c @@ -56,6 +56,7 @@ struct mne mne[] = { { NULL, ".org", S_ORG, 0, 0 }, { NULL, ".module", S_MODUL, 0, 0 }, { NULL, ".ascis", S_ASCIS, 0, 0 }, + { NULL, ".optsdcc", S_OPTSDCC, 0, 0}, /* z80 / hd64180 */ diff --git a/link/z80/aslink.h b/link/z80/aslink.h index 0e3cd39c..8a268546 100644 --- a/link/z80/aslink.h +++ b/link/z80/aslink.h @@ -452,6 +452,10 @@ extern char ctype[]; /* array of character types, one per * ASCII character */ +extern char sdccopt[NINPUT]; +extern char sdccopt_module[NINPUT]; +extern char curr_module[NINPUT]; + /* * Character Type Definitions */ diff --git a/link/z80/lkdata.c b/link/z80/lkdata.c index b9565417..0442ef75 100644 --- a/link/z80/lkdata.c +++ b/link/z80/lkdata.c @@ -38,6 +38,11 @@ char *rp; /* pointer into the LST file char rb[NINPUT]; /* LST file text line being * address relocated */ + +char sdccopt[NINPUT]=""; +char sdccopt_module[NINPUT]=""; +char curr_module[NINPUT]=""; + int oflag; /* Output file type flag */ int mflag; /* Map output flag diff --git a/link/z80/lklibr.c b/link/z80/lklibr.c index eb4cd98d..832af6f5 100644 --- a/link/z80/lklibr.c +++ b/link/z80/lklibr.c @@ -177,16 +177,16 @@ addlib() if (lbphead == NULL) { - foundcount+=addfile(NULL, ip); + foundcount=addfile(NULL, ip); } else { for (lbph=lbphead; lbph; lbph=lbph->next) { - foundcount+=addfile(lbph->path,ip); + foundcount+=addfile(lbph->path, ip); } } - if(foundcount==0) + if(foundcount == 0) { printf("\n?ASlink-Warning-Couldn't find library '%s'", ip); } diff --git a/link/z80/lkmain.c b/link/z80/lkmain.c index cf1b4745..c6cc8b29 100644 --- a/link/z80/lkmain.c +++ b/link/z80/lkmain.c @@ -488,6 +488,29 @@ link() if ((c=endline()) == 0) { return; } switch (c) { + case 'O': /*For some important sdcc options*/ + if (pass == 0) + { + if(strlen(sdccopt)==0) + { + strcpy(sdccopt, &ip[1]); + strcpy(sdccopt_module, curr_module); + } + else + { + if(strcmp(sdccopt, &ip[1])!=0) + { + fprintf(stderr, + "?ASlink-Warning-Conflicting sdcc options:\n" + " \"%s\" in module \"%s\" and\n" + " \"%s\" in module \"%s\".\n", + sdccopt, sdccopt_module, &ip[1], curr_module); + lkerr++; + } + } + } + break; + case 'X': radix = 16; break; @@ -517,7 +540,10 @@ link() case 'M': if (pass == 0) + { + strcpy(curr_module, &ip[1]); module(); + } break; case 'A': diff --git a/src/SDCCglue.c b/src/SDCCglue.c index bb9425b3..69d4b453 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -1572,6 +1572,33 @@ glue (void) /* print module name */ tfprintf (asmFile, "\t!module\n", spacesToUnderscores (moduleBuf, moduleName, sizeof moduleBuf)); + if(mcs51_like) + { + fprintf (asmFile, "\t.optsdcc -m%s", port->target); + + switch(options.model) + { + case MODEL_SMALL: fprintf (asmFile, " --model-small"); break; + case MODEL_COMPACT: fprintf (asmFile, " --model-compact"); break; + case MODEL_MEDIUM: fprintf (asmFile, " --model-medium"); break; + case MODEL_LARGE: fprintf (asmFile, " --model-large"); break; + case MODEL_FLAT24: fprintf (asmFile, " --model-flat24"); break; + case MODEL_PAGE0: fprintf (asmFile, " --model-page0"); break; + default: break; + } + if(options.stackAuto) fprintf (asmFile, " --stack-auto"); + if(options.useXstack) fprintf (asmFile, " --xstack"); + if(options.intlong_rent) fprintf (asmFile, " --int-long-rent"); + if(options.float_rent) fprintf (asmFile, " --float-rent"); + if(options.noRegParams) fprintf (asmFile, " --no-reg-params"); + if(options.parms_in_bank1) fprintf (asmFile, " --parms-in-bank1"); + fprintf (asmFile, "\n"); + } + else if(TARGET_IS_Z80 || TARGET_IS_GBZ80 ) + { + fprintf (asmFile, "\t.optsdcc -m%s\n", port->target); + } + tfprintf (asmFile, "\t!fileprelude\n"); /* Let the port generate any global directives, etc. */ -- 2.30.2