public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* .eh_frame section
@ 1997-10-07 23:14 Bruno Haible
  1997-10-07 23:14 ` Jason Merrill
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Haible @ 1997-10-07 23:14 UTC (permalink / raw)
  To: Jason Merrill

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.  */




^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: .eh_frame section
@ 1997-10-08 15:38 meissner
  1997-10-08 21:19 ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: meissner @ 1997-10-08 15:38 UTC (permalink / raw)
  To: jason, rth; +Cc: egcs, haible

| On Tue, Oct 07, 1997 at 10:42:08PM -0700, Jason Merrill wrote:
| > Richard was muttering something about a possibly suitable reloc style the
| > other day, but I don't remember the upshot.
| 
| Most architectures have a word sized pc-relative relocation, but few
| (none?) provide a pseudo-op to use it.  So there we are.

On the other hand, doing:

	.long .-label

(or .word, .etc.) will often times generate the approprate relocation.

You can even say:

	.L1:
		.long .L1-label1
		.long .L1-label2
		.long .L1-label3

for switch statements that contain PC-relative offsets.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* .eh_frame section
@ 2007-05-29 21:33 sfora dim
  2007-05-29 23:13 ` Ian Lance Taylor
  0 siblings, 1 reply; 13+ messages in thread
From: sfora dim @ 2007-05-29 21:33 UTC (permalink / raw)
  To: gcc

Hello,

I read that the eh_frame is for exceptions support,
for languages like C++ for instance.

I wonder why when I compile standard C programs using "gcc -v simple.c"
I can see that the linker adds the "--eh-frame-hdr" parameter ?

After all there is no use for the eh section when we don't support
exceptions, no ?

thank you
sfora

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

end of thread, other threads:[~2007-05-30  5:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-07 23:14 .eh_frame section Bruno Haible
1997-10-07 23:14 ` Jason Merrill
1997-10-08  9:24   ` Richard Henderson
1997-10-08 15:38 meissner
1997-10-08 21:19 ` Richard Henderson
1997-10-09  9:26   ` Ian Lance Taylor
1997-10-09  9:26     ` Jason Merrill
1997-10-10 17:21       ` Bruno Haible
1997-10-13  9:44         ` Joern Rennecke
1997-10-13 13:41           ` Richard Henderson
2007-05-29 21:33 sfora dim
2007-05-29 23:13 ` Ian Lance Taylor
2007-05-30  7:41   ` sfora dim

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).