public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
* .gas.warning sections
@ 1995-12-02 12:57 Arne H. Juul
  1995-12-02 13:49 ` Roland McGrath
  1995-12-04  8:25 ` Ian Lance Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: Arne H. Juul @ 1995-12-02 12:57 UTC (permalink / raw)
  To: gas2

I have been looking at getting warnings from gnu ld when
used on mips-dec-netbsd platform (this is "plain" ELF on
little-endian mips).  This deals with both GCC, the assembler
and the linker, so forgive me if this message is rather long-winded.

So from looking in the GNU libc it looks like this should be
done like in this simple example:

#define link_warning(symbol, msg)                       \
  static const char __evoke_link_warning_##symbol[]     \
    __attribute__ ((section (".gnu.warning." #symbol))) = msg;

link_warning(null1, "This program uses null1(), which is pointless.\n");
int null1(void) {}

At first, this doesn't get through gcc, I just get
"section attributes are not supported for this target".  From
looking at c-common.c this is because ASM_OUTPUT_SECTION_NAME,
which should mean that the target platform doesn't support
arbitrarily named sections.

Now in config/mips the only file defining ASM_OUTPUT_SECTION_NAME
is elf64.h, which has this code in it:

/* A C statement to output something to the assembler file to switch to section
   NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
   NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
   define this macro in such cases.  */

#define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME) \
do {                                                            \
  extern FILE *asm_out_text_file;                               \
  if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)              \
    fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
  else if ((DECL) && TREE_READONLY (DECL))                      \
    fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME));     \
  else                                                          \
    fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME));    \
} while (0)

This is probably really an assembler question:  Is all this stuff really
necessary, and what does the extra @progbits mean?  Stuffing this
code into netbsd.h as well seemed to work ok, but then I looked a bit
further, and while svr4.h has a somewhat simple version of this,
h8300/h8300.h has something more like what I had imagined:
#define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
  fprintf (FILE, "\t.section %s\n", NAME)

Stuffing this code into netbsd.h instead seemed to work just as well.
I would welcome enlightenment on this issue. (Maybe it should
be common code in config/mips/something.h?)

Another (maybe somewhat irrelevant) inquiry:  With any of the
two variants above gcc accepts my test file and gas produces an
object file with the required section.  When linking a 'main'-type
file which uses the symbol in question (null1 for my example)
I also get my warning:
tm.o: In function `main':
tm.c(.text+0x28): This program uses null1(), which is pointless.

However, if I change my test file to have *only* the warning section
for null1 (not the function definition itself), I get the following
behaviour:

gcc: Internal compiler error: program ld got fatal signal 6

This is if the program doesn't reference null1() at all.
If I do reference null1() it works right:

tm.o: In function `main':
tm.c(.text+0x28): This program uses null1(), which is pointless.
tm.c(.text+0x28): undefined reference to `null1'

This seems to be a (probably obscure) bug in ld, but hopefully it
shouldn't give me any "real" problems, right?

Yours,
  - Arne H. Juul


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: .gas.warning sections
  1995-12-02 12:57 .gas.warning sections Arne H. Juul
@ 1995-12-02 13:49 ` Roland McGrath
  1995-12-04  8:25 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Roland McGrath @ 1995-12-02 13:49 UTC (permalink / raw)
  To: arnej; +Cc: gas2

> At first, this doesn't get through gcc, I just get
> "section attributes are not supported for this target".  From
> looking at c-common.c this is because ASM_OUTPUT_SECTION_NAME,
> which should mean that the target platform doesn't support
> arbitrarily named sections.

That's right.  This should be defined by the tm.h file.  It seems there is
no existing GCC target which is set up for proper use of ELF on MIPS.

> Now in config/mips the only file defining ASM_OUTPUT_SECTION_NAME
> is elf64.h, which has this code in it:
>
> /* A C statement to output something to the assembler file to switch to section
>    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
>    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
>    define this macro in such cases.  */
>
> #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME) \
> do {                                                            \
>   extern FILE *asm_out_text_file;                               \
>   if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)              \
>     fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
>   else if ((DECL) && TREE_READONLY (DECL))                      \
>     fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME));     \
>   else                                                          \
>     fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME));    \
> } while (0)

That code also appears in config/svr4.h; its purpose is to select the right
section attributes based on the symbol being defined.  If it is a function,
the section is read-only, executable; if it is a read-only variable, the
section is read-only data; if it is a writable variable, the section is
read/write data.

The @progbits could probably be omitted, but its purpose in the ELF
.section directive is to indicate the type of data in the section is
program data (as opposed to symbols or debugging info or somesuch).

> Stuffing this code into netbsd.h instead seemed to work just as well.
> I would welcome enlightenment on this issue. (Maybe it should
> be common code in config/mips/something.h?)

It would be lovely if there were a config/mips/svr4.h or somesuch, for the
various MIPS platforms that use ELF and SVR4 shared libraries.  Kazumoto
Kojima <kkojima@info.kanagawa-u.ac.jp> may have done some work in this
area, in his port to the mips-gnu platform.

> Another (maybe somewhat irrelevant) inquiry:  With any of the
> two variants above gcc accepts my test file and gas produces an
> object file with the required section.  When linking a 'main'-type
> file which uses the symbol in question (null1 for my example)
> I also get my warning:
> tm.o: In function `main':
> tm.c(.text+0x28): This program uses null1(), which is pointless.
>
> However, if I change my test file to have *only* the warning section
> for null1 (not the function definition itself), I get the following
> behaviour:
>
> gcc: Internal compiler error: program ld got fatal signal 6

This is clearly an ld bug.  Are you using binutils 2.6?  You should report
this bug to bug-gnu-utils so it can be fixed.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: .gas.warning sections
  1995-12-02 12:57 .gas.warning sections Arne H. Juul
  1995-12-02 13:49 ` Roland McGrath
@ 1995-12-04  8:25 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 1995-12-04  8:25 UTC (permalink / raw)
  To: arnej; +Cc: gas2

   From: "Arne H. Juul" <arnej@pvv.unit.no>
   Date: Sat, 2 Dec 1995 21:57:49 +0100

   #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME) \
   do {                                                            \
     extern FILE *asm_out_text_file;                               \
     if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)              \
       fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
     else if ((DECL) && TREE_READONLY (DECL))                      \
       fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME));     \
     else                                                          \
       fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME));    \
   } while (0)

   This is probably really an assembler question:  Is all this stuff really
   necessary, and what does the extra @progbits mean?

Yes, all that stuff is really necessary.  I'm not sure why you say the
@progbits is extra.  It means that the section contains data that
forms part of the program image; by way of comparison, a DWARF
debugging section contains data, but it is not part of the program
image.  This ASM_OUTPUT_SECTION_NAME macro is very similar to the one
in config/svr4.h, except that it uses asm_out_text_file instead of F
when selecting the section for a function declaration.  This is
required for the way the MIPS backend handles global pointer
optimizations.

   Stuffing this
   code into netbsd.h as well seemed to work ok, but then I looked a bit
   further, and while svr4.h has a somewhat simple version of this,
   h8300/h8300.h has something more like what I had imagined:
   #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
     fprintf (FILE, "\t.section %s\n", NAME)

It's definitely best to tell the assembler the flags and type to give
the section.  It never hurts, and sometimes it is required.  You also
need to keep the asm_out_text_file distinction in order for functions
to be put in the right place.

   However, if I change my test file to have *only* the warning section
   for null1 (not the function definition itself), I get the following
   behaviour:

   gcc: Internal compiler error: program ld got fatal signal 6

This is a linker bug.  Here's the patch.

Ian

Index: elflink.h
===================================================================
RCS file: /cvs/cvsfiles/devo/bfd/elflink.h,v
retrieving revision 1.21
diff -u -r1.21 elflink.h
--- elflink.h	1995/12/01 19:47:51	1.21
+++ elflink.h	1995/12/04 16:14:12
@@ -2508,6 +2508,12 @@
 
     case bfd_link_hash_indirect:
     case bfd_link_hash_warning:
+      /* We can't represent these symbols in ELF.  A warning symbol
+         may have come from a .gnu.warning.SYMBOL section anyhow.  We
+         just put the target symbol in the hash table.  If the target
+         symbol does not really exist, don't do anything.  */
+      if (h->root.u.i.link->type == bfd_link_hash_new)
+	return true;
       return (elf_link_output_extsym
 	      ((struct elf_link_hash_entry *) h->root.u.i.link, data));
     }


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-12-04  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-12-02 12:57 .gas.warning sections Arne H. Juul
1995-12-02 13:49 ` Roland McGrath
1995-12-04  8:25 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).