Re: ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2001-01-04 Thread John Polstra

In article [EMAIL PROTECTED],
Russell L. Carter [EMAIL PROTECTED] wrote:
 
 Bingo!
 
 Thanks guys!

Not so fast there, fella.  You're not getting off that easily. ;-)
Could you please try the patch below?  It is like the patch that Paul
sent, except it should handle error conditions better.

This patch is against -current, but I think it will apply cleanly to
-stable too.

Thanks,
John

Index: rtld.c
===
RCS file: /home/ncvs/src/libexec/rtld-elf/rtld.c,v
retrieving revision 1.50
diff -u -r1.50 rtld.c
--- rtld.c  2000/11/07 22:41:53 1.50
+++ rtld.c  2001/01/05 00:13:18
@@ -77,6 +77,8 @@
 static Obj_Entry *digest_phdr(const Elf_Phdr *, int, caddr_t, const char *);
 static Obj_Entry *dlcheck(void *);
 static bool donelist_check(DoneList *, const Obj_Entry *);
+static void errmsg_restore(char *);
+static char *errmsg_save(void);
 static char *find_library(const char *, const Obj_Entry *);
 static const char *gethints(void);
 static void init_dag(Obj_Entry *);
@@ -457,6 +459,30 @@
 va_end(ap);
 }
 
+/*
+ * Return a dynamically-allocated copy of the current error message, if any.
+ */
+static char *
+errmsg_save(void)
+{
+return error_message == NULL ? NULL : xstrdup(error_message);
+}
+
+/*
+ * Restore the current error message from a copy which was previously saved
+ * by errmsg_save().  The copy is freed.
+ */
+static void
+errmsg_restore(char *saved_msg)
+{
+if (saved_msg == NULL)
+   error_message = NULL;
+else {
+   _rtld_error("%s", saved_msg);
+   free(saved_msg);
+}
+}
+
 static const char *
 basename(const char *name)
 {
@@ -696,7 +722,7 @@
if (obj == (Obj_Entry *) handle)
break;
 
-if (obj == NULL || obj-dl_refcount == 0) {
+if (obj == NULL || obj-refcount == 0 || obj-dl_refcount == 0) {
_rtld_error("Invalid shared object handle %p", handle);
return NULL;
 }
@@ -1184,13 +1210,20 @@
 objlist_call_fini(Objlist *list)
 {
 Objlist_Entry *elm;
+char *saved_msg;
 
+/*
+ * Preserve the current error message since a fini function might
+ * call into the dynamic linker and overwrite it.
+ */
+saved_msg = errmsg_save();
 STAILQ_FOREACH(elm, list, link) {
if (elm-obj-refcount == 0) {
dbg("calling fini function for %s", elm-obj-path);
(*elm-obj-fini)();
}
 }
+errmsg_restore(saved_msg);
 }
 
 /*
@@ -1202,11 +1235,18 @@
 objlist_call_init(Objlist *list)
 {
 Objlist_Entry *elm;
+char *saved_msg;
 
+/*
+ * Preserve the current error message since an init function might
+ * call into the dynamic linker and overwrite it.
+ */
+saved_msg = errmsg_save();
 STAILQ_FOREACH(elm, list, link) {
dbg("calling init function for %s", elm-obj-path);
(*elm-obj-init)();
 }
+errmsg_restore(saved_msg);
 }
 
 static void
@@ -2030,7 +2070,8 @@
 {
 const Needed_Entry *needed;
 
-assert(root-refcount != 0);
+if (root-refcount == 0)
+   return;
 root-refcount--;
 if (root-refcount == 0)
for (needed = root-needed;  needed != NULL;  needed = needed-next)


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2001-01-04 Thread Russell L. Carter

%In article [EMAIL PROTECTED],
%Russell L. Carter [EMAIL PROTECTED] wrote:
% 
% Bingo!
% 
% Thanks guys!
%
%Not so fast there, fella.  You're not getting off that easily. ;-)
%Could you please try the patch below?  It is like the patch that Paul
%sent, except it should handle error conditions better.
%
%This patch is against -current, but I think it will apply cleanly to
%-stable too.

My pleasure.  This patch applies cleanly against a two day old
-stable, and works just as well as the first patch, i.e., my
program works as expected.

Thanks!
Russell

%Thanks,
%John
%
%Index: rtld.c
%===
%RCS file: /home/ncvs/src/libexec/rtld-elf/rtld.c,v
%retrieving revision 1.50
%diff -u -r1.50 rtld.c
%--- rtld.c 2000/11/07 22:41:53 1.50
%+++ rtld.c 2001/01/05 00:13:18
%@@ -77,6 +77,8 @@
% static Obj_Entry *digest_phdr(const Elf_Phdr *, int, caddr_t, const char *);
% static Obj_Entry *dlcheck(void *);
% static bool donelist_check(DoneList *, const Obj_Entry *);
%+static void errmsg_restore(char *);
%+static char *errmsg_save(void);
% static char *find_library(const char *, const Obj_Entry *);
% static const char *gethints(void);
% static void init_dag(Obj_Entry *);
%@@ -457,6 +459,30 @@
% va_end(ap);
% }
% 
%+/*
%+ * Return a dynamically-allocated copy of the current error message, if any.
%+ */
%+static char *
%+errmsg_save(void)
%+{
%+return error_message == NULL ? NULL : xstrdup(error_message);
%+}
%+
%+/*
%+ * Restore the current error message from a copy which was previously saved
%+ * by errmsg_save().  The copy is freed.
%+ */
%+static void
%+errmsg_restore(char *saved_msg)
%+{
%+if (saved_msg == NULL)
%+  error_message = NULL;
%+else {
%+  _rtld_error("%s", saved_msg);
%+  free(saved_msg);
%+}
%+}
%+
% static const char *
% basename(const char *name)
% {
%@@ -696,7 +722,7 @@
%   if (obj == (Obj_Entry *) handle)
%   break;
% 
%-if (obj == NULL || obj-dl_refcount == 0) {
%+if (obj == NULL || obj-refcount == 0 || obj-dl_refcount == 0) {
%   _rtld_error("Invalid shared object handle %p", handle);
%   return NULL;
% }
%@@ -1184,13 +1210,20 @@
% objlist_call_fini(Objlist *list)
% {
% Objlist_Entry *elm;
%+char *saved_msg;
% 
%+/*
%+ * Preserve the current error message since a fini function might
%+ * call into the dynamic linker and overwrite it.
%+ */
%+saved_msg = errmsg_save();
% STAILQ_FOREACH(elm, list, link) {
%   if (elm-obj-refcount == 0) {
%   dbg("calling fini function for %s", elm-obj-path);
%   (*elm-obj-fini)();
%   }
% }
%+errmsg_restore(saved_msg);
% }
% 
% /*
%@@ -1202,11 +1235,18 @@
% objlist_call_init(Objlist *list)
% {
% Objlist_Entry *elm;
%+char *saved_msg;
% 
%+/*
%+ * Preserve the current error message since an init function might
%+ * call into the dynamic linker and overwrite it.
%+ */
%+saved_msg = errmsg_save();
% STAILQ_FOREACH(elm, list, link) {
%   dbg("calling init function for %s", elm-obj-path);
%   (*elm-obj-init)();
% }
%+errmsg_restore(saved_msg);
% }
% 
% static void
%@@ -2030,7 +2070,8 @@
% {
% const Needed_Entry *needed;
% 
%-assert(root-refcount != 0);
%+if (root-refcount == 0)
%+  return;
% root-refcount--;
% if (root-refcount == 0)
%   for (needed = root-needed;  needed != NULL;  needed = needed-next)
%
%
%To Unsubscribe: send mail to [EMAIL PROTECTED]
%with "unsubscribe freebsd-hackers" in the body of the message
%




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2001-01-04 Thread John Polstra

 %Could you please try the patch below?  It is like the patch that Paul
 %sent, except it should handle error conditions better.
 %
 %This patch is against -current, but I think it will apply cleanly to
 %-stable too.
 
 My pleasure.  This patch applies cleanly against a two day old
 -stable, and works just as well as the first patch, i.e., my
 program works as expected.

Thanks, Russell!  I'll commit it to -current and MFC in a few days.

John
-- 
  John Polstra   [EMAIL PROTECTED]
  John D. Polstra  Co., Inc.Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2000-12-30 Thread Russell L. Carter


Bingo!

Thanks guys!
Russell


%John Polstra ([EMAIL PROTECTED]) wrote:
% In article [EMAIL PROTECTED],
% Russell L. Carter [EMAIL PROTECTED] wrote:
%  
%  On a fairly recent -STABLE I am getting this failure:
%  
%  ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033
%  
%  I assume I'm doing something stupid, however the same code
%  works on Linux gcc-2.95.2, so I'm looking for what the 
%  difference might be.
%  
%  The program is an ACE/TAO C++ program that dlsym()s an object,
%  uses it happily, and then gets the assertion when dlclose()ing
%  from the containing object's dtor. 
%  
%  The assertion is that the refcount != 0.  What should I
%  do to fix that?
% 
% There is a bug in the dynamic linker in connection with calling dlopen
% or dlclose from a static constructor or destructor, and this sounds
% like it's related to that.  I came up with a fix for it which Peter
% Wemm was testing at Yahoo.  That was a few months ago, and I'll have
% to dig it out again after the holiday madness has subsided.  If you
% haven't heard from me by Saturday Jan. 6, I'd appreciate a gentle
% reminder to [EMAIL PROTECTED].
%
%Do you mean this patch?
%--- rtld.c 2000/08/01 07:17:54 1.1.1.3
%+++ rtld.c 2000/09/05 22:16:49 1.2
%@@ -694,7 +694,7 @@
%   if (obj == (Obj_Entry *) handle)
%   break;
% 
%-if (obj == NULL || obj-dl_refcount == 0) {
%+if (obj == NULL || obj-refcount == 0 || obj-dl_refcount == 0) {
%   _rtld_error("Invalid shared object handle %p", handle);
%   return NULL;
% }
%@@ -1994,6 +1994,8 @@
% {
% const Needed_Entry *needed;
% 
%+if (root-refcount == 0)
%+  return;
% assert(root-refcount != 0);
% root-refcount--;
% if (root-refcount == 0)
%
%-- 
%Paul Saab
%Technical Yahoo
[EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED]
%Do You .. uhh .. Yahoo!?
%
%
%To Unsubscribe: send mail to [EMAIL PROTECTED]
%with "unsubscribe freebsd-hackers" in the body of the message
%




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2000-12-29 Thread Russell L. Carter


Greetings,
On a fairly recent -STABLE I am getting this failure:

ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

I assume I'm doing something stupid, however the same code
works on Linux gcc-2.95.2, so I'm looking for what the 
difference might be.

The program is an ACE/TAO C++ program that dlsym()s an object,
uses it happily, and then gets the assertion when dlclose()ing
from the containing object's dtor. 

The assertion is that the refcount != 0.  What should I
do to fix that?

Thanks!
Russell



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033

2000-12-29 Thread John Polstra

In article [EMAIL PROTECTED],
Russell L. Carter [EMAIL PROTECTED] wrote:
 
 On a fairly recent -STABLE I am getting this failure:
 
 ld-elf.so.1: assert failed: /usr/src/libexec/rtld-elf/rtld.c:2033
 
 I assume I'm doing something stupid, however the same code
 works on Linux gcc-2.95.2, so I'm looking for what the 
 difference might be.
 
 The program is an ACE/TAO C++ program that dlsym()s an object,
 uses it happily, and then gets the assertion when dlclose()ing
 from the containing object's dtor. 
 
 The assertion is that the refcount != 0.  What should I
 do to fix that?

There is a bug in the dynamic linker in connection with calling dlopen
or dlclose from a static constructor or destructor, and this sounds
like it's related to that.  I came up with a fix for it which Peter
Wemm was testing at Yahoo.  That was a few months ago, and I'll have
to dig it out again after the holiday madness has subsided.  If you
haven't heard from me by Saturday Jan. 6, I'd appreciate a gentle
reminder to [EMAIL PROTECTED].

John
-- 
  John Polstra   [EMAIL PROTECTED]
  John D. Polstra  Co., Inc.Seattle, Washington USA
  "Disappointment is a good sign of basic intelligence."  -- Chögyam Trungpa



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message