This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Make the compiler do the math.


Hi all,

This patch implements the idea I presented in:
http://sourceware.org/ml/binutils/2006-09/msg00069.html

The idea is to replace cases where the string len is
calculated by to programmer, which is error prone, like this:
  "string", 6

with a macro that handles the job to the compiler, like this:
  STR_STRLEN_PAIR("string")

Instead of putting it in some global header like in the
original post, I defined a custom version for pe-dll.c.

This file is particularly filed with examples of str/strlen pairs,
and was the file I had in mind when I said the codebase is full
of examples.

Please review and commit.

---

2006-09-11 Pedro Alves <pedro_alves@portugalmail.pt>

	* pe-dll.c (AFET): New macro.
        (autofilter_symbollist_generic): Use AFET.
	(autofilter_symbollist_i386): Likewise.
	(autofilter_liblist): Likewise.
	(autofilter_objlist): Likewise.
	(autofilter_symbolprefixlist): Likewise.
	(autofilter_symbolsuffixlist): Likewise.



--- pe-dll.c.org	2006-09-11 20:06:27.000000000 +0100
+++ pe-dll.c	2006-09-11 20:59:28.000000000 +0100
@@ -150,6 +150,8 @@ typedef struct
 }
 autofilter_entry_type;
 
+#define AFET(STR) { (STR), ((STR)? sizeof (STR) - 1 : 0) }
+
 typedef struct
 {
   char *target_name;
@@ -164,42 +166,42 @@ pe_details_type;
 
 static autofilter_entry_type autofilter_symbollist_generic[] =
 {
-  { ".text", 5 },
+  AFET(".text"),
   /* Entry point symbols.  */
-  { "DllMain", 7 },
-  { "DllMainCRTStartup", 17 },
-  { "_DllMainCRTStartup", 18 },
+  AFET("DllMain"),
+  AFET("DllMainCRTStartup"),
+  AFET("_DllMainCRTStartup"),
   /* Runtime pseudo-reloc.  */
-  { "_pei386_runtime_relocator", 25 },
-  { "do_pseudo_reloc", 15 },
-  { NULL, 0 }
+  AFET("_pei386_runtime_relocator"),
+  AFET("do_pseudo_reloc"),
+  AFET(NULL)
 };
 
 static autofilter_entry_type autofilter_symbollist_i386[] =
 {
-  { ".text", 5 },
+  AFET(".text"),
   /* Entry point symbols, and entry hooks.  */
-  { "cygwin_crt0", 11 },
-  { "DllMain@12", 10 },
-  { "DllEntryPoint@0", 15 },
-  { "DllMainCRTStartup@12", 20 },
-  { "_cygwin_dll_entry@12", 20 },
-  { "_cygwin_crt0_common@8", 21 },
-  { "_cygwin_noncygwin_dll_entry@12", 30 },
-  { "cygwin_attach_dll", 17 },
-  { "cygwin_premain0", 15 },
-  { "cygwin_premain1", 15 },
-  { "cygwin_premain2", 15 },
-  { "cygwin_premain3", 15 },
+  AFET("cygwin_crt0"),
+  AFET("DllMain@12"),
+  AFET("DllEntryPoint@0"),
+  AFET("DllMainCRTStartup@12"),
+  AFET("_cygwin_dll_entry@12"),
+  AFET("_cygwin_crt0_common@8"),
+  AFET("_cygwin_noncygwin_dll_entry@12"),
+  AFET("cygwin_attach_dll"),
+  AFET("cygwin_premain0"),
+  AFET("cygwin_premain1"),
+  AFET("cygwin_premain2"),
+  AFET("cygwin_premain3"),
   /* Runtime pseudo-reloc.  */
-  { "_pei386_runtime_relocator", 25 },
-  { "do_pseudo_reloc", 15 },
+  AFET("_pei386_runtime_relocator"),
+  AFET("do_pseudo_reloc"),
   /* Global vars that should not be exported.  */
-  { "impure_ptr", 10 },
-  { "_impure_ptr", 11 },
-  { "_fmode", 6 },
-  { "environ", 7 },
-  { NULL, 0 }
+  AFET("impure_ptr"),
+  AFET("_impure_ptr"),
+  AFET("_fmode"),
+  AFET("environ"),
+  AFET(NULL)
 };
 
 #define PE_ARCH_i386	 1
@@ -273,51 +275,51 @@ static pe_details_type *pe_details;
 /* Do not specify library suffix explicitly, to allow for dllized versions.  */
 static autofilter_entry_type autofilter_liblist[] =
 {
-  { "libcegcc", 8 },
-  { "libcygwin", 9 },
-  { "libgcc", 6 },
-  { "libstdc++", 9 },
-  { "libmingw32", 10 },
-  { "libmingwex", 10 },
-  { "libg2c", 6 },
-  { "libsupc++", 9 },
-  { "libobjc", 7 },
-  { "libgcj", 6 },
-  { NULL, 0 }
+  AFET("libcegcc") ,
+  AFET("libcygwin"),
+  AFET("libgcc"),
+  AFET("libstdc++"),
+  AFET("libmingw32"),
+  AFET("libmingwex"),
+  AFET("libg2c"),
+  AFET("libsupc++"),
+  AFET("libobjc"),
+  AFET("libgcj"),
+  AFET(NULL)
 };
 
 static autofilter_entry_type autofilter_objlist[] =
 {
-  { "crt0.o", 6 },
-  { "crt1.o", 6 },
-  { "crt2.o", 6 },
-  { "dllcrt1.o", 9 },
-  { "dllcrt2.o", 9 },
-  { "gcrt0.o", 7 },
-  { "gcrt1.o", 7 },
-  { "gcrt2.o", 7 },
-  { "crtbegin.o", 10 },
-  { "crtend.o", 8 },
-  { NULL, 0 }
+  AFET("crt0.o"),
+  AFET("crt1.o"),
+  AFET("crt2.o"),
+  AFET("dllcrt1.o"),
+  AFET("dllcrt2.o"),
+  AFET("gcrt0.o"),
+  AFET("gcrt1.o"),
+  AFET("gcrt2.o"),
+  AFET("crtbegin.o"),
+  AFET("crtend.o"),
+  AFET(NULL)
 };
 
 static autofilter_entry_type autofilter_symbolprefixlist[] =
 {
-  { "__imp_", 6 },
+  AFET("__imp_"),
   /* Do __imp_ explicitly to save time.  */
-  { "__rtti_", 7 },
+  AFET("__rtti_"),
   /* Don't re-export auto-imported symbols.  */
-  { "_nm_", 4 },
-  { "__builtin_", 10 },
+  AFET("_nm_"),
+  AFET("__builtin_"),
   /* Don't export symbols specifying internal DLL layout.  */
-  { "_head_", 6 },
-  { NULL, 0 }
+  AFET("_head_"),
+  AFET(NULL)
 };
 
 static autofilter_entry_type autofilter_symbolsuffixlist[] =
 {
-  { "_iname", 6 },
-  { NULL, 0 }
+  AFET("_iname"),
+  AFET(NULL)
 };
 
 #define U(str) (pe_details->underscored ? "_" str : str)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]