summaryrefslogtreecommitdiffstats
path: root/lib/csu/i386/c++rt0.c
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1996-01-15 17:53:25 +0000
committerjdp <jdp@FreeBSD.org>1996-01-15 17:53:25 +0000
commit83a650d90c7424446b3b768820ba6def8b151593 (patch)
treeaaf9386dd73c53d4496e061a04769e110b4e26b3 /lib/csu/i386/c++rt0.c
parentad0d6ac8dbc83a7e965ca6a28eb4ae8e5822cec9 (diff)
downloadFreeBSD-src-83a650d90c7424446b3b768820ba6def8b151593.zip
FreeBSD-src-83a650d90c7424446b3b768820ba6def8b151593.tar.gz
Check the count in the first word of __CTOR_LIST__ before executing
the loop that invokes the static constructors. That makes it safe to link c++rt0.o into any shared library, even one that does not have any static constructors. Formerly, doing that would cause a bus error. If the library has no static constructors, __CTOR_LIST__ comes out as a simple 4-byte COMMON region, and it does not have the usual NULL word that terminates the list of constructors. This caused the old code to "call" a garbage address via the non-existent entry __CTOR_LIST__[1]. The analogous code that invokes the static destructors was already safe. This change is fully backward-compatible. Reviewed by: dfr@render.com (Doug Rabson)
Diffstat (limited to 'lib/csu/i386/c++rt0.c')
-rw-r--r--lib/csu/i386/c++rt0.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/csu/i386/c++rt0.c b/lib/csu/i386/c++rt0.c
index aa28109..40cc5fa 100644
--- a/lib/csu/i386/c++rt0.c
+++ b/lib/csu/i386/c++rt0.c
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: c++rt0.c,v 1.2 1995/05/30 05:39:36 rgrimes Exp $
+ * $Id: c++rt0.c,v 1.3 1995/06/27 09:53:24 dfr Exp $
*/
/*
@@ -54,10 +54,18 @@ __dtors(void)
static void
__ctors(void)
{
- void (**p)(void) = __CTOR_LIST__ + 1;
+ /*
+ * If the shared library doesn't have any static constructors in it,
+ * then __CTOR_LIST__ will come out as a simple COMMON region of
+ * 4 bytes. That is why we have to check the count in the first
+ * word.
+ */
+ if ((unsigned long) __CTOR_LIST__[0] > 0) {
+ void (**p)(void) = __CTOR_LIST__ + 1;
- while (*p)
- (**p++)();
+ while (*p)
+ (**p++)();
+ }
}
extern void __init() asm(".init");
OpenPOWER on IntegriCloud