This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
.eh_frame section
- To: Jason Merrill <jason at cygnus dot com>
- Subject: .eh_frame section
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 6 Oct 1997 16:06:48 +0200 (MET DST)
- >Received: from halles.ilog.fr (halles.ilog.fr [172.16.1.96])by ilog.ilog.fr (8.8.7/8.7.3) with ESMTP id QAA27591;Mon, 6 Oct 1997 16:06:48 +0200 (MET DST)
- Xref: yorick.cygnus.com mail.work:3403
Hi,
Currently the ".eh_frame" section (containing DWARF2 unwind info) is
a read-write section. This poses two problems:
1. Accidental write accesses to this area by buggy programs won't be
caught. Instead such a program is likely to go to nirvana when the
next __throw occurs.
Please find below a patch which makes the ".eh_frame" section read-only
when compiling non-PIC (on those systems for which I could guess how to
implement it).
2. The ".eh_frame" section takes up about 25% of an executable. For
an executable, this is nothing to worry about. But for a shared
library, "objdump --section-headers" shows that the .eh_frame
section has the attributes CONTENTS, ALLOC, LOAD, RELOC, DATA.
The combination LOAD, RELOC means that, on most Unix systems,
this section will be completely read in and relocated when
the shared library is mapped into the process memory, i.e. usually
at program startup. Here at ILOG, we are routinely using executables
which are linked to a total of 20 MB of shared libraries. If 25%
of this must be read from disk each time the program starts up,
that will certainly be noticeable...
Would it be possible to replace the `pc_begin' pointer and the
`CIE_pointer' in `struct dwarf_fde' by position-independent entities?
Best regards,
Bruno
Sun Oct 5 03:07:30 1997 Bruno Haible <bruno@linuix.mathematik.uni-karlsruhe.de>
* sysv4.h (EH_FRAME_SECTION_ASM_OP, READONLY_EH_FRAME_SECTION_ASM_OP):
New macros.
* sparc/sysv4.h (READONLY_EH_FRAME_SECTION_ASM_OP): Likewise.
* mips/iris6.h (READONLY_EH_FRAME_SECTION_ASM_OP): Likewise.
* varasm.c (eh_frame_section): Use READONLY_EH_FRAME_SECTION_ASM_OP
unless compiling in PIC mode.
* crtstuff.c: Likewise.
*** config/mips/iris6.h.bak Sat Sep 27 01:33:40 1997
--- config/mips/iris6.h Sun Oct 5 00:03:12 1997
***************
*** 251,256 ****
--- 251,257 ----
/* dwarf2out will handle padding this data properly. We definitely don't
want it 8-byte aligned on n32. */
#define EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,1,2,0,1"
+ #define READONLY_EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,1,2,0,1"
/* A default list of other sections which we might be "in" at any given
time. For targets that use additional sections (e.g. .tdesc) you
*** config/sparc/sysv4.h.bak Sat Sep 27 01:35:49 1997
--- config/sparc/sysv4.h Sat Oct 4 23:59:59 1997
***************
*** 177,182 ****
--- 177,184 ----
#define DTORS_SECTION_ASM_OP ".section\t\".dtors\",#alloc,#write"
#undef EH_FRAME_SECTION_ASM_OP
#define EH_FRAME_SECTION_ASM_OP ".section\t\".eh_frame\",#alloc,#write"
+ #undef READONLY_EH_FRAME_SECTION_ASM_OP
+ #define READONLY_EH_FRAME_SECTION_ASM_OP ".section\t\".eh_frame\",#alloc"
/* 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
*** config/svr4.h.bak Wed Apr 30 19:59:24 1997
--- config/svr4.h Sun Oct 5 01:49:55 1997
***************
*** 527,532 ****
--- 527,539 ----
#define CTORS_SECTION_ASM_OP ".section\t.ctors,\"aw\""
#define DTORS_SECTION_ASM_OP ".section\t.dtors,\"aw\""
+ /* Put DWARF2 unwind info into a section with SHF_WRITE attribute set if
+ we are compiling for a shared library, but in a read-only section if we
+ are compiling code for an executable. */
+
+ #define EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,\"aw\""
+ #define READONLY_EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,\"a\""
+
/* On svr4, we *do* have support for the .init and .fini sections, and we
can put stuff in there to be executed before and after `main'. We let
crtstuff.c and other files know this by defining the following symbols.
*** crtstuff.c.bak Sat Sep 27 01:33:59 1997
--- crtstuff.c Sun Oct 5 01:10:57 1997
***************
*** 79,84 ****
--- 79,87 ----
#if !defined (EH_FRAME_SECTION_ASM_OP) && defined (DWARF2_UNWIND_INFO) && defined(ASM_OUTPUT_SECTION_NAME)
#define EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,\"aw\""
#endif
+ #if !defined (READONLY_EH_FRAME_SECTION_ASM_OP) && defined (DWARF2_UNWIND_INFO) && defined(ASM_OUTPUT_SECTION_NAME)
+ #define READONLY_EH_FRAME_SECTION_ASM_OP ".section\t.eh_frame,\"a\""
+ #endif
#ifdef OBJECT_FORMAT_ELF
***************
*** 286,292 ****
--- 289,300 ----
/* Stick a label at the beginning of the frame unwind info so we can register
and deregister it with the exception handling library code. */
+ #ifdef __PIC__
asm (EH_FRAME_SECTION_ASM_OP);
+ #else
+ asm (READONLY_EH_FRAME_SECTION_ASM_OP);
+ #endif
+
#ifdef INIT_SECTION_ASM_OP
STATIC
#endif
***************
*** 421,427 ****
--- 429,440 ----
this would be the 'length' field in a real FDE. */
typedef unsigned int ui32 __attribute__ ((mode (SI)));
+ #ifdef __PIC__
asm (EH_FRAME_SECTION_ASM_OP);
+ #else
+ asm (READONLY_EH_FRAME_SECTION_ASM_OP);
+ #endif
+
STATIC ui32 __FRAME_END__[] = { 0 };
#endif /* EH_FRAME_SECTION */
*** varasm.c.bak Sat Sep 27 01:36:58 1997
--- varasm.c Sun Oct 5 01:58:21 1997
***************
*** 410,416 ****
{
if (in_section != in_eh_frame)
{
! fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
in_section = in_eh_frame;
}
}
--- 410,419 ----
{
if (in_section != in_eh_frame)
{
! if (flag_pic)
! fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
! else
! fprintf (asm_out_file, "%s\n", READONLY_EH_FRAME_SECTION_ASM_OP);
in_section = in_eh_frame;
}
}
*** output.h.bak Sat Sep 27 01:30:36 1997
--- output.h Sat Oct 4 23:54:39 1997
***************
*** 150,155 ****
--- 150,158 ----
/* Tell assembler to switch to the section for the exception table. */
extern void exception_section PROTO((void));
+ /* Tell assembler to switch to the section for the eh_frame info table. */
+ extern void eh_frame_section PROTO((void));
+
/* Create the rtl to represent a function, for a function definition.
DECL is a FUNCTION_DECL node which describes which function.
The rtl is stored into DECL. */