gnupic: gpasm `extern' vs `global' (new feature patch)
Subject:
Re: gpasm `extern' vs `global' (new feature patch)
From:
Craig Franklin ####@####.####
Date:
21 Apr 2005 04:15:21 +0100
Message-Id: <42686C53.2050603@users.sourceforge.net>
Ian Jackson wrote:
>I found it inconvenient that when defining a global symbol (one with
>`external linkage' in C parlance, although there is of course no C
>here) in gpasm I have to say `global', but when I'm referring to it I
>have to say `extern'. That means I can't have one include file with a
>list of all of the global symbols.
>
>So, I wrote the patch below which is supposed to allow the use of
>`extern' even for symbols defined in the same file, at least for
>labels. (You have to say `extern' before the label.) When the
>definition is encountered the symbol is converted from extern to
>global. This appears to work for me.
>
>I'd be grateful if you'd let me know what you think of it, and I would
>be very happy if it were included in future gputils versions.
>
>
>
It seems like a reasonable request. Give me a few days to run some
tests and think about the consequences.
>The patch was made against Debian's gputils 0.13.1-1. This will be
>very similar to upstream 0.13.1. Note though that due to a bug in
>0.13.1-1 I'm actually using 0.12.4-1 to which the patch also applies
>cleanly.
>
>
>
Are you referring to this?
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=305547
I don't generally review gputils bug reports on the debian tracker. In
the future, it would be better if the bug was added to gputils
sourceforge or reported to me.
I will try to take a look at the bug tomorrow.
>One oddity was that I had to use fprintf(stderr,...) for my
>diagnostic. It's not clear that a diagnostic is warranted - I just
>wanted to know that my code was working. It should probably be taken
>out at some point. I tried using gpmessage but gpmessage only works
>on pass 2 and this message about promoting an `extern' to a `global'
>is only issued during pass 1 because the promotion happens only once,
>the first time the label definition is processed.
>
>Thanks,
>Ian.
>
>diff --exclude Makefile --exclude config.log --exclude config.status -ru orig/gputils-0.13.1/gpasm/coff.c gputils-0.13.1/gpasm/coff.c
>--- orig/gputils-0.13.1/gpasm/coff.c Mon Jan 3 22:21:04 2005
>+++ gputils-0.13.1/gpasm/coff.c Wed Apr 20 17:39:57 2005
>@@ -447,7 +447,7 @@
> if ((new->type != class) ||
> (new->section_number != section_number)) {
> snprintf(message, sizeof(message),
>- "Duplicate label or redefining symbol that cannot be redefined. (%s)",
>+ "Duplicate extern label or redefining symbol that cannot be redefined. (%s)",
> name);
> gperror(GPE_UNKNOWN, message);
> }
>@@ -455,7 +455,7 @@
>
> if ((new != NULL) && (type != gvt_extern) && (type != gvt_debug)) {
> snprintf(message, sizeof(message),
>- "Duplicate label or redefining symbol that cannot be redefined. (%s)",
>+ "Duplicate non-extern label or redefining symbol that cannot be redefined. (%s)",
> name);
> gperror(GPE_DUPLAB, message);
> } else {
>Only in gputils-0.13.1/gpasm: coff.c~
>Only in gputils-0.13.1/gpasm: gperror.h~
>diff --exclude Makefile --exclude config.log --exclude config.status -ru orig/gputils-0.13.1/gpasm/util.c gputils-0.13.1/gpasm/util.c
>--- orig/gputils-0.13.1/gpasm/util.c Mon Jan 3 22:21:19 2005
>+++ gputils-0.13.1/gpasm/util.c Wed Apr 20 18:14:00 2005
>@@ -160,6 +160,7 @@
> if (sym == NULL)
> sym = add_symbol(state.stGlobal, name);
> var = get_symbol_annotation(sym);
>+
> if (var == NULL) {
> /* new symbol */
> var = malloc(sizeof(*var));
>@@ -184,6 +185,11 @@
> */
> var->value = value;
>
>+ } else if (type == gvt_extern && var->type == gvt_global) {
>+ /* Ignore `extern' directies for things that we have actually
>+ * seen defined and which therefore became global.
>+ */
>+
> } else if (state.pass == 2) {
> char *coff_name;
>
>@@ -201,6 +207,17 @@
>
> if (coff_name != NULL)
> free(coff_name);
>+
>+ } else if (type == gvt_address && var->type == gvt_extern) {
>+ char message[BUFSIZ];
>+
>+ fprintf(stderr,
>+ "Symbol \"%s\" declared extern but defined as address by"
>+ " use as label, making global\n", name);
>+
>+ var->type = gvt_global;
>+ var->value = value;
>+
> }
>
> /* increment the index into the coff symbol table for the relocations */
>Only in gputils-0.13.1/gpasm: util.c~
>
>
>