binutils221: final solution to start/stop label generation
authorJohn Marino <draco@marino.st>
Thu, 7 Apr 2011 22:14:07 +0000 (00:14 +0200)
committerJohn Marino <draco@marino.st>
Thu, 7 Apr 2011 22:14:07 +0000 (00:14 +0200)
During discussion on binutils mail list about preserving the
__start_* and __stop_* section labels, Dimitry Andric indicated that
FreeBSD had the same exact issue when they recently upgraded to
binutils 2.17.50.  The solution they chose was to declare these section
labels as global symbols, and the stock version of ld will retain them.

This commit implements the FreeBSD solution.  Besides the obvious
benefit of having minimalist shared objects, it also "fixes" binutils
2.20 which, until this commit, failed to generate the start/stop section
labels.

Commit f070647cc5317c4924be4dd60563fc39c18094cf has been reverted to
convert binutils 2.21 to a completely stock ld.  Some whitespace cleanup
of linker_set.h was done while modifying __MAKE_SET macro.

contrib/binutils-2.21/README.DRAGONFLY
contrib/binutils-2.21/ld/ldlang.c
sys/sys/cdefs.h
sys/sys/linker_set.h
usr.sbin/mfiutil/mfiutil.h

index 6dfd951..b839636 100644 (file)
@@ -39,5 +39,4 @@
        bfd/config.bfd
        binutils/arlex.l
        gas/config/tc-i386.c
-       ld/ldlang.c
        ld/ldlex.l
index a895521..7256495 100644 (file)
@@ -1757,15 +1757,10 @@ lang_insert_orphan (asection *s,
          e_align = exp_unop (ALIGN_K,
                              exp_intop ((bfd_vma) 1 << s->alignment_power));
          lang_add_assignment (exp_assign (".", e_align));
-         if (link_info.shared)
-           lang_add_assignment (exp_assign (symname,
-                                             exp_unop (ABSOLUTE,
-                                               exp_nameop (NAME, "."))));
-          else
-            lang_add_assignment (exp_provide (symname,
-                                             exp_unop (ABSOLUTE,
-                                                exp_nameop (NAME, ".")),
-                                             FALSE));
+         lang_add_assignment (exp_provide (symname,
+                                           exp_unop (ABSOLUTE,
+                                                     exp_nameop (NAME, ".")),
+                                           FALSE));
        }
     }
 
@@ -1795,13 +1790,9 @@ lang_insert_orphan (asection *s,
       symname = (char *) xmalloc (ps - secname + sizeof "__stop_" + 1);
       symname[0] = bfd_get_symbol_leading_char (link_info.output_bfd);
       sprintf (symname + (symname[0] != 0), "__stop_%s", secname);
-      if (link_info.shared)
-        lang_add_assignment (exp_assign (symname,
-                                        exp_nameop (NAME, ".")));
-      else
-        lang_add_assignment (exp_provide (symname,
-                                          exp_nameop (NAME, "."),
-                                          FALSE));
+      lang_add_assignment (exp_provide (symname,
+                                       exp_nameop (NAME, "."),
+                                       FALSE));
     }
 
   /* Restore the global list pointer.  */
index bd95f0f..ce92186 100644 (file)
 #endif
 #endif
 
+/*
+ * GLOBL macro exists to preserve __start_set_* and __stop_set_* sections
+ * of kernel modules which are discarded from binutils 2.17.50+ otherwise.
+ */
+
+#define        __GLOBL1(sym)   __asm__(".globl " #sym)
+#define        __GLOBL(sym)    __GLOBL1(sym)
+
 #endif /* !_SYS_CDEFS_H_ */
index 1ce3322..eb7b17d 100644 (file)
 
 #endif
 
-#define __MAKE_SET(set, sym)                                            \
-        static void const * const __set_##set##_sym_##sym               \
+#define __MAKE_SET(set, sym)                                           \
+       __GLOBL(__CONCAT(__start_set_,set));                            \
+       __GLOBL(__CONCAT(__stop_set_,set));                             \
+       static void const * const __set_##set##_sym_##sym               \
        __section("set_" #set) __used = &sym
 
 #define TEXT_SET(set, sym) __MAKE_SET(set, sym)
index 1cf01ca..9a2d3db 100644 (file)
@@ -49,6 +49,8 @@
 #undef DATA_SET
 
 #define __MAKE_SET(set, sym)                                           \
+       __GLOBL(__CONCAT(__start_set_,set));                            \
+       __GLOBL(__CONCAT(__stop_set_,set));                             \
        static void const * const __set_##set##_sym_##sym               \
        __section("set_" #set) __used = &sym