* [PATCH] cvexpr.c: Don't let linker delete unused globals
@ 2002-04-18 6:23 Kevin Buettner
2002-04-18 11:14 ` Michael Snyder
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2002-04-18 6:23 UTC (permalink / raw)
To: gdb-patches
On AIX, I was seeing lots of failures in gdb.base/code-expr.exp and
gdb.base/cvexpr.exp due to the fact that the linker deletes unused
symbols. The patch below fixes these failures.
Committed as obvious.
* gdb.base/cvexpr.c (use): New function.
(main): Invoke use() on all global variables to prevent
some linkers from deleting these otherwise unused symbols.
Index: cvexpr.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/cvexpr.c,v
retrieving revision 1.1
diff -u -p -r1.1 cvexpr.c
--- cvexpr.c 15 Nov 2001 02:16:59 -0000 1.1
+++ cvexpr.c 18 Apr 2002 12:59:53 -0000
@@ -273,8 +273,162 @@ unsigned long long (*v_unsigned_long_lon
float (*v_float_func) (int, int*);
double (*v_double_func) (int, int*);
-
+void use (void *p)
+{
+}
int main ()
{
+ use (&v_char);
+ use (&v_signed_char);
+ use (&v_unsigned_char);
+
+ use (&v_short);
+ use (&v_signed_short);
+ use (&v_unsigned_short);
+
+ use (&v_int);
+ use (&v_signed_int);
+ use (&v_unsigned_int);
+
+ use (&v_long);
+ use (&v_signed_long);
+ use (&v_unsigned_long);
+
+ use (&v_long_long);
+ use (&v_signed_long_long);
+ use (&v_unsigned_long_long);
+
+ use (&v_float);
+ use (&v_double);
+
+ use (v_char_array);
+ use (v_signed_char_array);
+ use (v_unsigned_char_array);
+
+ use (v_short_array);
+ use (v_signed_short_array);
+ use (v_unsigned_short_array);
+
+ use (v_int_array);
+ use (v_signed_int_array);
+ use (v_unsigned_int_array);
+
+ use (v_long_array);
+ use (v_signed_long_array);
+ use (v_unsigned_long_array);
+
+ use (v_float_array);
+ use (v_double_array);
+
+ use (v_char_pointer);
+ use (v_signed_char_pointer);
+ use (v_unsigned_char_pointer);
+
+ use (v_short_pointer);
+ use (v_signed_short_pointer);
+ use (v_unsigned_short_pointer);
+
+ use (v_int_pointer);
+ use (v_signed_int_pointer);
+ use (v_unsigned_int_pointer);
+
+ use (v_long_pointer);
+ use (v_signed_long_pointer);
+ use (v_unsigned_long_pointer);
+
+ use (v_float_pointer);
+ use (v_double_pointer);
+
+ use (v_char_pointer_pointer);
+ use (v_signed_char_pointer_pointer);
+ use (v_unsigned_char_pointer_pointer);
+
+ use (v_short_pointer_pointer);
+ use (v_signed_short_pointer_pointer);
+ use (v_unsigned_short_pointer_pointer);
+
+ use (v_int_pointer_pointer);
+ use (v_signed_int_pointer_pointer);
+ use (v_unsigned_int_pointer_pointer);
+
+ use (v_long_pointer_pointer);
+ use (v_signed_long_pointer_pointer);
+ use (v_unsigned_long_pointer_pointer);
+
+ use (v_float_pointer_pointer);
+ use (v_double_pointer_pointer);
+
+ use (v_char_array_pointer);
+ use (v_signed_char_array_pointer);
+ use (v_unsigned_char_array_pointer);
+
+ use (v_short_array_pointer);
+ use (v_signed_short_array_pointer);
+ use (v_unsigned_short_array_pointer);
+
+ use (v_int_array_pointer);
+ use (v_signed_int_array_pointer);
+ use (v_unsigned_int_array_pointer);
+
+ use (v_long_array_pointer);
+ use (v_signed_long_array_pointer);
+ use (v_unsigned_long_array_pointer);
+
+ use (v_float_array_pointer);
+ use (v_double_array_pointer);
+
+ use (v_char_pointer_array);
+ use (v_signed_char_pointer_array);
+ use (v_unsigned_char_pointer_array);
+
+ use (v_short_pointer_array);
+ use (v_signed_short_pointer_array);
+ use (v_unsigned_short_pointer_array);
+
+ use (v_int_pointer_array);
+ use (v_signed_int_pointer_array);
+ use (v_unsigned_int_pointer_array);
+
+ use (v_long_pointer_array);
+ use (v_signed_long_pointer_array);
+ use (v_unsigned_long_pointer_array);
+
+ use (v_float_pointer_array);
+ use (v_double_pointer_array);
+
+ use (&v_struct1);
+ use (&v_struct2);
+ use (&v_struct3);
+
+ use (&v_union);
+ use (&v_union2);
+ use (&v_union3);
+
+ use (&v_boolean);
+ use (&v_boolean2);
+ use (&v_misordered);
+
+ use (v_char_func);
+ use (v_signed_char_func);
+ use (v_unsigned_char_func);
+
+ use (v_short_func);
+ use (v_signed_short_func);
+ use (v_unsigned_short_func);
+
+ use (v_int_func);
+ use (v_signed_int_func);
+ use (v_unsigned_int_func);
+
+ use (v_long_func);
+ use (v_signed_long_func);
+ use (v_unsigned_long_func);
+
+ use (v_long_long_func);
+ use (v_signed_long_long_func);
+ use (v_unsigned_long_long_func);
+
+ use (v_float_func);
+ use (v_double_func);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cvexpr.c: Don't let linker delete unused globals
2002-04-18 6:23 [PATCH] cvexpr.c: Don't let linker delete unused globals Kevin Buettner
@ 2002-04-18 11:14 ` Michael Snyder
2002-04-18 11:49 ` Kevin Buettner
0 siblings, 1 reply; 3+ messages in thread
From: Michael Snyder @ 2002-04-18 11:14 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches
Kevin Buettner wrote:
>
> On AIX, I was seeing lots of failures in gdb.base/code-expr.exp and
> gdb.base/cvexpr.exp due to the fact that the linker deletes unused
> symbols. The patch below fixes these failures.
>
> Committed as obvious.
Wow, that's really sad, to have to add all that code
for such a trivial reason. I'm sure there are other
tests in gdb.base that also make use of symbols that
don't get called. Isn't there some option that you can
give to the linker to tell it not to remove these?
>
> * gdb.base/cvexpr.c (use): New function.
> (main): Invoke use() on all global variables to prevent
> some linkers from deleting these otherwise unused symbols.
>
> Index: cvexpr.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/testsuite/gdb.base/cvexpr.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 cvexpr.c
> --- cvexpr.c 15 Nov 2001 02:16:59 -0000 1.1
> +++ cvexpr.c 18 Apr 2002 12:59:53 -0000
> @@ -273,8 +273,162 @@ unsigned long long (*v_unsigned_long_lon
> float (*v_float_func) (int, int*);
> double (*v_double_func) (int, int*);
>
> -
> +void use (void *p)
> +{
> +}
>
> int main ()
> {
> + use (&v_char);
> + use (&v_signed_char);
> + use (&v_unsigned_char);
> +
> + use (&v_short);
> + use (&v_signed_short);
> + use (&v_unsigned_short);
> +
> + use (&v_int);
> + use (&v_signed_int);
> + use (&v_unsigned_int);
> +
> + use (&v_long);
> + use (&v_signed_long);
> + use (&v_unsigned_long);
> +
> + use (&v_long_long);
> + use (&v_signed_long_long);
> + use (&v_unsigned_long_long);
> +
> + use (&v_float);
> + use (&v_double);
> +
> + use (v_char_array);
> + use (v_signed_char_array);
> + use (v_unsigned_char_array);
> +
> + use (v_short_array);
> + use (v_signed_short_array);
> + use (v_unsigned_short_array);
> +
> + use (v_int_array);
> + use (v_signed_int_array);
> + use (v_unsigned_int_array);
> +
> + use (v_long_array);
> + use (v_signed_long_array);
> + use (v_unsigned_long_array);
> +
> + use (v_float_array);
> + use (v_double_array);
> +
> + use (v_char_pointer);
> + use (v_signed_char_pointer);
> + use (v_unsigned_char_pointer);
> +
> + use (v_short_pointer);
> + use (v_signed_short_pointer);
> + use (v_unsigned_short_pointer);
> +
> + use (v_int_pointer);
> + use (v_signed_int_pointer);
> + use (v_unsigned_int_pointer);
> +
> + use (v_long_pointer);
> + use (v_signed_long_pointer);
> + use (v_unsigned_long_pointer);
> +
> + use (v_float_pointer);
> + use (v_double_pointer);
> +
> + use (v_char_pointer_pointer);
> + use (v_signed_char_pointer_pointer);
> + use (v_unsigned_char_pointer_pointer);
> +
> + use (v_short_pointer_pointer);
> + use (v_signed_short_pointer_pointer);
> + use (v_unsigned_short_pointer_pointer);
> +
> + use (v_int_pointer_pointer);
> + use (v_signed_int_pointer_pointer);
> + use (v_unsigned_int_pointer_pointer);
> +
> + use (v_long_pointer_pointer);
> + use (v_signed_long_pointer_pointer);
> + use (v_unsigned_long_pointer_pointer);
> +
> + use (v_float_pointer_pointer);
> + use (v_double_pointer_pointer);
> +
> + use (v_char_array_pointer);
> + use (v_signed_char_array_pointer);
> + use (v_unsigned_char_array_pointer);
> +
> + use (v_short_array_pointer);
> + use (v_signed_short_array_pointer);
> + use (v_unsigned_short_array_pointer);
> +
> + use (v_int_array_pointer);
> + use (v_signed_int_array_pointer);
> + use (v_unsigned_int_array_pointer);
> +
> + use (v_long_array_pointer);
> + use (v_signed_long_array_pointer);
> + use (v_unsigned_long_array_pointer);
> +
> + use (v_float_array_pointer);
> + use (v_double_array_pointer);
> +
> + use (v_char_pointer_array);
> + use (v_signed_char_pointer_array);
> + use (v_unsigned_char_pointer_array);
> +
> + use (v_short_pointer_array);
> + use (v_signed_short_pointer_array);
> + use (v_unsigned_short_pointer_array);
> +
> + use (v_int_pointer_array);
> + use (v_signed_int_pointer_array);
> + use (v_unsigned_int_pointer_array);
> +
> + use (v_long_pointer_array);
> + use (v_signed_long_pointer_array);
> + use (v_unsigned_long_pointer_array);
> +
> + use (v_float_pointer_array);
> + use (v_double_pointer_array);
> +
> + use (&v_struct1);
> + use (&v_struct2);
> + use (&v_struct3);
> +
> + use (&v_union);
> + use (&v_union2);
> + use (&v_union3);
> +
> + use (&v_boolean);
> + use (&v_boolean2);
> + use (&v_misordered);
> +
> + use (v_char_func);
> + use (v_signed_char_func);
> + use (v_unsigned_char_func);
> +
> + use (v_short_func);
> + use (v_signed_short_func);
> + use (v_unsigned_short_func);
> +
> + use (v_int_func);
> + use (v_signed_int_func);
> + use (v_unsigned_int_func);
> +
> + use (v_long_func);
> + use (v_signed_long_func);
> + use (v_unsigned_long_func);
> +
> + use (v_long_long_func);
> + use (v_signed_long_long_func);
> + use (v_unsigned_long_long_func);
> +
> + use (v_float_func);
> + use (v_double_func);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cvexpr.c: Don't let linker delete unused globals
2002-04-18 11:14 ` Michael Snyder
@ 2002-04-18 11:49 ` Kevin Buettner
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Buettner @ 2002-04-18 11:49 UTC (permalink / raw)
To: Michael Snyder, Kevin Buettner; +Cc: gdb-patches
On Apr 18, 10:02am, Michael Snyder wrote:
> > On AIX, I was seeing lots of failures in gdb.base/code-expr.exp and
> > gdb.base/cvexpr.exp due to the fact that the linker deletes unused
> > symbols. The patch below fixes these failures.
> >
> > Committed as obvious.
>
> Wow, that's really sad, to have to add all that code
> for such a trivial reason. I'm sure there are other
> tests in gdb.base that also make use of symbols that
> don't get called.
Yeah. I ran across some of these in the past and added some similar
looking code. E.g, here's a ChangeLog entry for one of them:
2000-03-21 Kevin Buettner <kevinb@redhat.com>
* gdb.base/pointers.c (usevar): New function.
(main): Make sure that global variables v_int_pointer2, rptr,
and y are all referenced someplace in the program by calling
usevar() on them. [Some linkers delete symbols which are
never referenced. The space remains, but there's no way to
get a (symbolic) handle on the variable from the debugger.]
> Isn't there some option that you can
> give to the linker to tell it not to remove these?
Apparently there is, but in my opinion, it's easier to maintain
changes to C code than bits of configury involving the linker
which can change over time. Also, the testsuite will just work
without the need to specify any additional linker options for
other (future) linkers which choose to also garbage collect unused
symbols.
Kevin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-04-18 18:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-18 6:23 [PATCH] cvexpr.c: Don't let linker delete unused globals Kevin Buettner
2002-04-18 11:14 ` Michael Snyder
2002-04-18 11:49 ` Kevin Buettner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox