From 166f84746d6c8e80a83cb1225bef286012000c8e Mon Sep 17 00:00:00 2001 From: Stephen McKay Date: Sat, 22 Aug 1998 15:51:41 +0000 Subject: [PATCH] Pass me the pointy hat with the extra sequins. Just a moment, while I get it to sit right... The __error() hack gave out the wrong address. It returned the address of errno in ld.so instead of the address of errno in the main program. Oops. The hack is now correct, just in time to be obsoleted by elf. --- libexec/rtld-aout/rtld.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/libexec/rtld-aout/rtld.c b/libexec/rtld-aout/rtld.c index 4ae4fa612c09..5e7843ef3868 100644 --- a/libexec/rtld-aout/rtld.c +++ b/libexec/rtld-aout/rtld.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: rtld.c,v 1.54 1998/06/07 03:53:06 brian Exp $ + * $Id: rtld.c,v 1.55 1998/06/21 14:22:29 mckay Exp $ */ #include @@ -1605,6 +1605,8 @@ sym_addr(name) } +static int *p_errno; /* Pointer to errno variable in main program. */ + /* * Help old a.out binaries that are broken by the new errno macro. They * can be missing __error() through no fault of their own. In particular, @@ -1625,6 +1627,21 @@ lookup_errno_hack(sym, src_map, real_def_only) if (strcmp(sym, "___error") != 0) return NULL; + /* + * Locate errno in the main program. If it's not there, NULL + * will be returned by our __error() substitute, and a core dump + * will follow. That's impossible, of course, since crt0.o always + * supplies errno. + */ + smp = NULL; + np = lookup("_errno", &smp, 1); + if (np != NULL && smp != NULL) { + p_errno = (int *)(smp->som_addr + np->nz_value); +#ifdef DEBUG + xprintf(" HACK: _errno at %p in %s\n", p_errno, smp->som_path); +#endif + } + /* * Specifically find the ld.so link map because most routines * skip over it during normal operation. @@ -1634,10 +1651,7 @@ lookup_errno_hack(sym, src_map, real_def_only) break; /* - * Actually, ld.so uses errno via the new macro, so it has a copy - * of __error() lying around. The really neat but obscure hack - * is to just use that one, but to be really clear about what - * is going on, we use an explicit __error() substitute. + * Find our __error() substitute stashed here in ld.so. */ np = lookup("___error_unthreaded_hack", &smp, real_def_only); if (np != NULL) @@ -1661,7 +1675,7 @@ lookup_errno_hack(sym, src_map, real_def_only) int * __error_unthreaded_hack() { - return &errno; + return p_errno; }