NetBSD Problem Report #10940

Received: (qmail 29075 invoked from network); 3 Sep 2000 15:57:31 -0000
Message-Id: <200009031556.e83FuDu00458@go61923.e-ly.com>
Date: Sun, 3 Sep 2000 16:56:13 +0100 (BST)
From: Nick Hudson <nick@nthcliff.demon.co.uk>
Reply-To: nick@nthcliff.demon.co.uk
To: gnats-bugs@gnats.netbsd.org
Subject: Writing to dlopened library variable core with i386/a.out
X-Send-Pr-Version: 3.95

>Number:         10940
>Category:       lib
>Synopsis:       Writing to dlopened library variable core with i386/a.out
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 03 15:58:00 +0000 2000
>Closed-Date:    Fri Apr 06 08:10:13 +0000 2001
>Last-Modified:  Fri Apr 06 08:10:13 +0000 2001
>Originator:     Nick Hudson
>Release:        NetBSD-1.4.2
>Organization:
>Environment:

System: NetBSD go61923 1.4.2 NetBSD

>Description:
	The attached shar includes a program that cores on i386/a.out, but not
	on i386/ELF.
>How-To-Repeat:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	.
#	./Makefile
#	./dltest
#	./dltest/main.c
#	./dltest/Makefile
#	./libfoo
#	./libfoo/foo1.c
#	./libfoo/Makefile
#	./libfoo/shlib_version
#
echo c - .
mkdir -p . > /dev/null 2>&1
echo x - ./Makefile
sed 's/^X//' >./Makefile << 'END-of-./Makefile'
XSUBDIR=	libfoo dltest
X
Xall:
X	dltest/dltest
X
X.include <bsd.subdir.mk>
END-of-./Makefile
echo c - ./dltest
mkdir -p ./dltest > /dev/null 2>&1
echo x - ./dltest/main.c
sed 's/^X//' >./dltest/main.c << 'END-of-./dltest/main.c'
X#include <dlfcn.h>
X#include <stdio.h>
X
X#ifdef __ELF__
X#define FUNC "func"
X#define VAR "var"
X#else
X#define FUNC "_func"
X#define VAR "_var"
X#endif
X
Xint
Xmain ()
X{
X  void * handle;	
X  void (*pfunc)() = 0;
X  int *pvar = 0;
X
X  handle = dlopen("./libfoo/libfoo.so.3.2", RTLD_GLOBAL | RTLD_LAZY);
X  if (!handle) {
X    fprintf (stderr, "can't open the module!\n");
X    fprintf (stderr, "error was: %s\n", dlerror());
X    exit(1);
X  }
X
X  pfunc = (void(*)())dlsym(handle, FUNC);  
X  if (pfunc)
X      (*pfunc) ();
X  else {
X      fprintf (stderr, "did not find the `func' function\n");
X      fprintf (stderr, "error was: %s\n", dlerror());
X      exit(1);
X  }
X
X  pvar = (int*)dlsym(handle, VAR);  
X  /* Try assigning to the var variable. */
X  if (pvar)
X    *pvar = 1;
X  else {
X      fprintf (stderr, "did not find the `var' variable\n");
X      fprintf (stderr, "error was: %s\n", dlerror());
X      exit(1);
X  }
X  return 0;
X}
END-of-./dltest/main.c
echo x - ./dltest/Makefile
sed 's/^X//' >./dltest/Makefile << 'END-of-./dltest/Makefile'
XPROG=		dltest
X
XSRCS=		main.c
XCPPFLAGS+=	-I${.CURDIR}/../libfoo
XLDFLAGS+=	-L${.CURDIR}/../libfoo
XCFLAGS+=	-g
X
XMKMAN=		no
X
X.include <bsd.prog.mk>
END-of-./dltest/Makefile
echo c - ./libfoo
mkdir -p ./libfoo > /dev/null 2>&1
echo x - ./libfoo/foo1.c
sed 's/^X//' >./libfoo/foo1.c << 'END-of-./libfoo/foo1.c'
X#include <stdio.h>
X
X/* Give a global variable definition. */
Xint var;
X
Xvoid
Xfunc()
X{
X  printf ("** This is func **\n");
X}
END-of-./libfoo/foo1.c
echo x - ./libfoo/Makefile
sed 's/^X//' >./libfoo/Makefile << 'END-of-./libfoo/Makefile'
XLIB=	foo
XSRCS=	foo1.c
X
XCFLAGS+=	-g
X
X.include <bsd.lib.mk>
END-of-./libfoo/Makefile
echo x - ./libfoo/shlib_version
sed 's/^X//' >./libfoo/shlib_version << 'END-of-./libfoo/shlib_version'
Xmajor=3
Xminor=2
END-of-./libfoo/shlib_version
exit

>Fix:
	Unknown.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: skrll 
State-Changed-When: Fri Apr 6 01:09:57 PDT 2001 
State-Changed-Why:  
ITOH Yasufumi <itohy@netbsd.org> committed a fix. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.