This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Committed: h8300: Issue a warning for new sections created without attributes
- From: Nick Clifton <nickc at redhat dot com>
- To: binutils at sourceware dot org
- Date: Wed, 13 Jan 2010 14:09:16 +0000
- Subject: Committed: h8300: Issue a warning for new sections created without attributes
Hi Guys,
I am applying the patch below to add a feature to the H8300 port of
GAS. If a new section is created without specifying any attributes
then a warning message will be issued. Well known sections (.text,
.data. .bss. etc) will not generate this message. This feature is to
help programmers who create new code sections but who forget to give
them an "executable" attribute. Doing this on the H8300 port results
in problems later on when relocs are generated and issuing the warning
message helps the programmers find the problem.
Cheers
Nick
gas/ChangeLog
2010-01-13 Nick Clifton <nickc@redhat.com>
* config/tc-h8300.c (h8300_elf_section): New function - issue a
warning message if a new section is created without setting any
attributes for it.
(md_pseudo_table): Intercept section creation pseudos.
(md_pcrel_from): Replace abort with an error message.
* config/obj-elf.c (obj_elf_section_name): Export this function.
* config/obj-elf.h (obj_elf_section_name): Prototype.
gas/testsuite/ChangeLog
2010-01-13 Nick Clifton <nickc@redhat.com>
* gas/elf/section0.d: Skip this test for the h8300.
* gas/elf/section1.d: Likewise.
* gas/elf/section6.d: Likewise.
* gas/elf/elf.exp: Skip section2 and section5 tests when the
target is the h8300.
ld/testsuite/ChangeLog
2010-01-13 Nick Clifton <nickc@redhat.com>
* ld-scrips/sort.exp: Skip these tests when the target is the
h8300.
Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.125
diff -c -3 -p -r1.125 obj-elf.c
*** gas/config/obj-elf.c 6 Nov 2009 11:51:04 -0000 1.125
--- gas/config/obj-elf.c 13 Jan 2010 14:02:47 -0000
*************** obj_elf_section_word (char *str, size_t
*** 855,861 ****
}
/* Get name of section. */
! static char *
obj_elf_section_name (void)
{
char *name;
--- 855,861 ----
}
/* Get name of section. */
! char *
obj_elf_section_name (void)
{
char *name;
Index: gas/config/obj-elf.h
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.h,v
retrieving revision 1.36
diff -c -3 -p -r1.36 obj-elf.h
*** gas/config/obj-elf.h 2 Sep 2009 07:24:20 -0000 1.36
--- gas/config/obj-elf.h 13 Jan 2010 14:02:47 -0000
*************** extern void elf_file_symbol (const char
*** 164,169 ****
--- 164,170 ----
extern void obj_elf_section_change_hook (void);
extern void obj_elf_section (int);
+ extern char * obj_elf_section_name (void);
extern void obj_elf_previous (int);
extern void obj_elf_version (int);
extern void obj_elf_common (int);
Index: gas/config/tc-h8300.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-h8300.c,v
retrieving revision 1.62
diff -c -3 -p -r1.62 tc-h8300.c
*** gas/config/tc-h8300.c 2 Sep 2009 07:24:20 -0000 1.62
--- gas/config/tc-h8300.c 13 Jan 2010 14:02:48 -0000
*************** pint (int arg ATTRIBUTE_UNUSED)
*** 139,144 ****
--- 139,186 ----
cons (Hmode ? 4 : 2);
}
+ /* Like obj_elf_section, but issues a warning for new
+ sections which do not have an attribute specification. */
+
+ static void
+ h8300_elf_section (int push)
+ {
+ static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
+ static const char * known_data_prefixes [] = { ".debug", ".gnu.warning" };
+ char * saved_ilp = input_line_pointer;
+ char * name;
+
+ name = obj_elf_section_name ();
+ if (name == NULL)
+ return;
+
+ if (* input_line_pointer != ','
+ && bfd_get_section_by_name (stdoutput, name) == NULL)
+ {
+ signed int i;
+
+ /* Ignore this warning for well known data sections. */
+ for (i = ARRAY_SIZE (known_data_sections); i--;)
+ if (strcmp (name, known_data_sections[i]) == 0)
+ break;
+
+ if (i < 0)
+ for (i = ARRAY_SIZE (known_data_prefixes); i--;)
+ if (strncmp (name, known_data_prefixes[i],
+ strlen (known_data_prefixes[i])) == 0)
+ break;
+
+ if (i < 0)
+ as_warn (_("new section '%s' defined without attributes - this might cause problems"), name);
+ }
+
+ /* FIXME: We ought to free the memory allocated by obj_elf_section_name()
+ for 'name', but we do not know if it was taken from the obstack, via
+ demand_copy_C_string(), or xmalloc()ed. */
+ input_line_pointer = saved_ilp;
+ obj_elf_section (push);
+ }
+
/* This table describes all the machine specific pseudo-ops the assembler
has to support. The fields are:
pseudo-op name without dot
*************** const pseudo_typeS md_pseudo_table[] =
*** 165,170 ****
--- 207,220 ----
{"import", s_ignore, 0},
{"page", listing_eject, 0},
{"program", s_ignore, 0},
+
+ #ifdef OBJ_ELF
+ {"section", h8300_elf_section, 0},
+ {"section.s", h8300_elf_section, 0},
+ {"sect", h8300_elf_section, 0},
+ {"sect.s", h8300_elf_section, 0},
+ #endif
+
{0, 0, 0}
};
*************** md_number_to_chars (char *ptr, valueT us
*** 2139,2147 ****
}
long
! md_pcrel_from (fixS *fixP ATTRIBUTE_UNUSED)
{
! abort ();
}
arelent *
--- 2189,2199 ----
}
long
! md_pcrel_from (fixS *fixp)
{
! as_bad_where (fixp->fx_file, fixp->fx_line,
! _("Unexpected reference to a symbol in a non-code section"));
! return 0;
}
arelent *
Index: gas/testsuite/gas/elf/elf.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/elf.exp,v
retrieving revision 1.55
diff -c -3 -p -r1.55 elf.exp
*** gas/testsuite/gas/elf/elf.exp 29 Sep 2009 14:17:09 -0000 1.55
--- gas/testsuite/gas/elf/elf.exp 13 Jan 2010 14:02:48 -0000
*************** if { ([istarget "*-*-*elf*"]
*** 126,135 ****
}
run_dump_test "section0"
run_dump_test "section1"
! run_elf_list_test "section2" "$target_machine" "-al" "-s" ""
run_dump_test "section3"
run_dump_test "section4"
! run_elf_list_test "section5" "" "-al" "-SW" "| grep \" \\\\.test\\\[0-9\\\]\""
run_dump_test "struct"
run_dump_test "symtab"
run_dump_test "symver"
--- 126,143 ----
}
run_dump_test "section0"
run_dump_test "section1"
! if {! [istarget "h8300-*-*"]} then {
! # The h8300 port issues a warning message for
! # new sections created without atrributes.
! run_elf_list_test "section2" "$target_machine" "-al" "-s" ""
! }
run_dump_test "section3"
run_dump_test "section4"
! if {! [istarget "h8300-*-*"]} then {
! # The h8300 port issues a warning message for
! # new sections created without atrributes.
! run_elf_list_test "section5" "" "-al" "-SW" "| grep \" \\\\.test\\\[0-9\\\]\""
! }
run_dump_test "struct"
run_dump_test "symtab"
run_dump_test "symver"
Index: gas/testsuite/gas/elf/section0.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/section0.d,v
retrieving revision 1.5
diff -c -3 -p -r1.5 section0.d
*** gas/testsuite/gas/elf/section0.d 8 Oct 2005 17:07:16 -0000 1.5
--- gas/testsuite/gas/elf/section0.d 13 Jan 2010 14:02:48 -0000
***************
*** 1,5 ****
--- 1,8 ----
#objdump: -s
#name: elf section0
+ # The h8300 port issues a warning message for
+ # new sections created without atrributes.
+ #skip: h8300-*
.*: +file format .*
Index: gas/testsuite/gas/elf/section1.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/section1.d,v
retrieving revision 1.5
diff -c -3 -p -r1.5 section1.d
*** gas/testsuite/gas/elf/section1.d 8 Oct 2005 17:07:16 -0000 1.5
--- gas/testsuite/gas/elf/section1.d 13 Jan 2010 14:02:48 -0000
***************
*** 1,5 ****
--- 1,8 ----
#objdump: -s
#name: elf section1
+ # The h8300 port issues a warning message for
+ # new sections created without atrributes.
+ #skip: h8300-*
.*: +file format .*
Index: gas/testsuite/gas/elf/section6.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/elf/section6.d,v
retrieving revision 1.1
diff -c -3 -p -r1.1 section6.d
*** gas/testsuite/gas/elf/section6.d 11 Oct 2007 20:20:55 -0000 1.1
--- gas/testsuite/gas/elf/section6.d 13 Jan 2010 14:02:48 -0000
***************
*** 1,5 ****
--- 1,8 ----
#objdump: -s
#name: elf section6
+ # The h8300 port issues a warning message for
+ # new sections created without atrributes.
+ #skip: h8300-*
.*: +file format .*
Index: ld/testsuite/ld-scripts/sort.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/sort.exp,v
retrieving revision 1.5
diff -c -3 -p -r1.5 sort.exp
*** ld/testsuite/ld-scripts/sort.exp 2 Sep 2009 07:25:41 -0000 1.5
--- ld/testsuite/ld-scripts/sort.exp 13 Jan 2010 14:02:50 -0000
*************** if ![is_elf_format] {
*** 25,30 ****
--- 25,36 ----
return
}
+ # The h8300 port issues a warning message for
+ # new sections created without atrributes.
+ if [istarget "h8300-*-*"] {
+ return
+ }
+
load_lib ld-lib.exp
set sort_test_list [lsort [glob -nocomplain $srcdir/$subdir/sort*.d]]