Subject:
Re: [gnupic] Re: gpasm `extern' vs `global' (new feature patch)
From:
####@####.#### (Ian Jackson)
Date:
16 Dec 2005 12:26:50 +0000
Message-Id: <17314.45691.606304.550014@chiark.greenend.org.uk>
In April, I 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.
And in October I wrote:
> So, after some head-scratching, I came up with an alternative - see
> below. With this new patch you have to say `extern' _after_ the
> definition. If you do, it treats the `extern' more or less as if it
> was `global'.
>
> This is a less friendly version of the patch than the previous one,
> IMO, but the way the coff symbol number calculation is done makes it
> impractical do it it another way.
I've been using my patched 0.13.3-1 gputils for the past few months
and this has been working well. I would like to suggest that my
patch, or something like it, be included in the next gputils release.
Thanks,
Ian.
diff -ru orig/gputils-0.13.3/debian/changelog gputils-0.13.3/debian/changelog
--- orig/gputils-0.13.3/debian/changelog 2005-10-28 00:02:21.754919510 +0100
+++ gputils-0.13.3/debian/changelog 2005-10-29 17:24:17.498756153 +0100
@@ -1,3 +1,13 @@
+gputils (0.13.3-1.0iwj2) unstable; urgency=low
+
+ * extern/global feature for labels:
+ If we encounter `extern' for a label which is already defined
+ as gvt_static or gvt_address, we change it to gvt_global.
+ This means that `extern' after a label definition is much like
+ `global'.
+
+ -- Ian Jackson ####@####.#### Sat, 29 Oct 2005 17:24:12 +0100
+
gputils (0.13.3-1) unstable; urgency=low
* New upstream version.
Only in gputils-0.13.3/debian: changelog~
diff -ru orig/gputils-0.13.3/gpasm/coff.c gputils-0.13.3/gpasm/coff.c
--- orig/gputils-0.13.3/gpasm/coff.c 2005-01-03 22:21:04.000000000 +0000
+++ gputils-0.13.3/gpasm/coff.c 2005-10-29 15:59:18.913415094 +0100
@@ -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 {
diff -ru orig/gputils-0.13.3/gpasm/directive.c gputils-0.13.3/gpasm/directive.c
--- orig/gputils-0.13.3/gpasm/directive.c 2005-07-02 18:10:13.000000000 +0100
+++ gputils-0.13.3/gpasm/directive.c 2005-10-29 17:06:08.431816728 +0100
@@ -1342,6 +1342,8 @@
struct pnode *parms)
{
char *p;
+ struct symbol *s;
+ struct variable *var;
state.lst.line.linetype = dir;
if (state.mode == absolute) {
@@ -1350,7 +1352,15 @@
for (; parms; parms = TAIL(parms)) {
p = maybe_evaluate_concat(HEAD(parms));
if (p) {
- set_global(p, 0, PERMANENT, gvt_extern);
+ s = get_symbol(state.stTop, p);
+ var = s ? get_symbol_annotation(s) : NULL;
+ if (var &&
+ (var->previous_type == gvt_static ||
+ var->previous_type == gvt_address)) {
+ var->type = gvt_global;
+ } else {
+ set_global(p, 0, PERMANENT, gvt_extern);
+ }
}
}
}