summary refs log tree commit diff
path: root/elf/vismain.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-05-23 18:12:52 +0000
committerUlrich Drepper <drepper@redhat.com>2000-05-23 18:12:52 +0000
commiteec8ef5a73e9a23aa8baedf6b5efc0dc8c077950 (patch)
treeca4477788182c9cb0513729d81ab1e8c46ea89bd /elf/vismain.c
parentc1025c1980cb29bf3b22267ad19c73603712610e (diff)
downloadglibc-eec8ef5a73e9a23aa8baedf6b5efc0dc8c077950.tar.gz
glibc-eec8ef5a73e9a23aa8baedf6b5efc0dc8c077950.tar.xz
glibc-eec8ef5a73e9a23aa8baedf6b5efc0dc8c077950.zip
Update.
2000-05-23  Ulrich Drepper  <drepper@redhat.com>

	* elf/Makefile (tests): Add $(tests-vis-$(have-protected)).
	(tests-vis-yes): Add vismain.
	(modules-names): Add $(modules-vis-$(have-protected)).
	(modules-vis-yes): Add vismod1, vismod2, and vismod3.
	Add rules to generate and run vismain.
	* elf/vismain.c: New file.
	* elf/vismod1.c: New file.
	* elf/vismod2.c: New file.
	* elf/vismod3.c: New file.
Diffstat (limited to 'elf/vismain.c')
-rw-r--r--elf/vismain.c266
1 files changed, 266 insertions, 0 deletions
diff --git a/elf/vismain.c b/elf/vismain.c
new file mode 100644
index 0000000000..f72c3e17a1
--- /dev/null
+++ b/elf/vismain.c
@@ -0,0 +1,266 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Prototypes for the functions in the DSOs.  */
+extern int calllocal1 (void);
+extern int (*getlocal1 (void)) (void);
+extern int callinmod1 (void);
+extern int (*getinmod1 (void)) (void);
+extern int callitcpt1 (void);
+extern int (*getitcpt1 (void)) (void);
+extern const char *getvarlocal1 (void);
+extern const char *getvarinmod1 (void);
+extern const char *getvaritcpt1 (void);
+extern int calllocal2 (void);
+extern int (*getlocal2 (void)) (void);
+extern int callinmod2 (void);
+extern int (*getinmod2 (void)) (void);
+extern int callitcpt2 (void);
+extern int (*getitcpt2 (void)) (void);
+extern const char *getvarlocal2 (void);
+extern const char *getvarinmod2 (void);
+extern const char *getvaritcpt2 (void);
+extern int callitcpt3 (void);
+extern int (*getitcpt3 (void)) (void);
+extern const char *getvaritcpt3 (void);
+
+extern int protinmod (void);
+extern int protitcpt (void);
+
+/* Prototypes for local functions.  */
+extern int protlocal (void);
+
+const char *protvarlocal = __FILE__;
+extern const char *protvarinmod;
+extern const char *protvaritcpt;
+
+int
+main (void)
+{
+  int res = 0;
+  int val;
+
+  /* First test: check whether .protected is handled correctly by the
+     assembler/linker.  The uses of `protlocal' in the DSOs and in the
+     main program should all be resolved with the local definitions.  */
+  val = protlocal () + calllocal1 () + calllocal2 ();
+  if (val != 0x155)
+    {
+      puts ("\
+The handling of `.protected' seems to be implemented incorrectly: giving up");
+      abort ();
+    }
+  puts ("`.protected' seems to be handled correctly, good!");
+
+  /* Function pointers: for functions which are marked local and for
+     which definitions are available all function pointers must be
+     distinct.  */
+  if (protlocal == getlocal1 ())
+    {
+      puts ("`protlocal' in main and mod1 have same address");
+      res = 1;
+    }
+  if (protlocal == getlocal2 ())
+    {
+      puts ("`protlocal' in main and mod2 have same address");
+      res = 1;
+    }
+  if (getlocal1 () == getlocal2 ())
+    {
+      puts ("`protlocal' in mod1 and mod2 have same address");
+      res = 1;
+    }
+  if (getlocal1 () () + getlocal2 () () != 0x44)
+    {
+      puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
+      res = 1;
+    }
+
+  /* Next test.  This is similar to the last one but the function we
+     are calling is not defined in the main object.  This means that
+     the invocation in the main object uses the definition in the
+     first DSO.  */
+  if (protinmod != getinmod1 ())
+    {
+      puts ("`protinmod' in main and mod1 don't have same address");
+      res = 1;
+    }
+  if (protinmod == getinmod2 ())
+    {
+      puts ("`protinmod' in main and mod2 have same address");
+      res = 1;
+    }
+  if (getinmod1 () == getinmod2 ())
+    {
+      puts ("`protinmod' in mod1 and mod2 have same address");
+      res = 1;
+    }
+  if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
+    {
+      puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
+      res = 1;
+    }
+  val = protinmod () + callinmod1 () + callinmod2 ();
+  if (val != 0x15800)
+    {
+      printf ("calling of `protinmod' leads to wrong result (%#x)\n", val);
+      res = 1;
+    }
+
+  /* A very similar text.  Same setup for the main object and the modules
+     but this time we have another definition in a preloaded module. This
+     one intercepts the references from the main object.  */
+  if (protitcpt != getitcpt3 ())
+    {
+      puts ("`protitcpt' in main and mod3 don't have same address");
+      res = 1;
+    }
+  if (protitcpt == getitcpt1 ())
+    {
+      puts ("`protitcpt' in main and mod1 have same address");
+      res = 1;
+    }
+  if (protitcpt == getitcpt2 ())
+    {
+      puts ("`protitcpt' in main and mod2 have same address");
+      res = 1;
+    }
+  if (getitcpt1 () == getitcpt2 ())
+    {
+      puts ("`protitcpt' in mod1 and mod2 have same address");
+      res = 1;
+    }
+  val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
+  if (val != 0x8440000)
+    {
+      printf ("\
+pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
+      res = 1;
+    }
+  val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
+  if (val != 0x19540000)
+    {
+      printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
+      res = 1;
+    }
+
+  /* Now look at variables.  First a variable which is available
+     everywhere.  We must have three different addresses.  */
+  if (protvarlocal == getvarlocal1 ())
+    {
+      puts ("`protvarlocal' in main and mod1 have same address");
+      res = 1;
+    }
+  if (protvarlocal == getvarlocal2 ())
+    {
+      puts ("`protvarlocal' in main and mod2 have same address");
+      res = 1;
+    }
+  if (getvarlocal1 () == getvarlocal2 ())
+    {
+      puts ("`protvarlocal' in mod1 and mod2 have same address");
+      res = 1;
+    }
+  if (strcmp (protvarlocal, __FILE__) != 0)
+    {
+      puts ("`protvarlocal in main has wrong value");
+      res = 1;
+    }
+  if (strcmp (getvarlocal1 (), "vismod1.c") != 0)
+    {
+      puts ("`getvarlocal1' returns wrong value");
+      res = 1;
+    }
+  if (strcmp (getvarlocal2 (), "vismod2.c") != 0)
+    {
+      puts ("`getvarlocal2' returns wrong value");
+      res = 1;
+    }
+
+  /* Now the case where there is no local definition.  */
+  if (protvarinmod != getvarinmod1 ())
+    {
+      puts ("`protvarinmod' in main and mod1 have not same address");
+      res = 1;
+    }
+  if (protvarinmod == getvarinmod2 ())
+    {
+      puts ("`protvarinmod' in main and mod2 have same address");
+      res = 1;
+    }
+  if (strcmp (getvarinmod1 (), "vismod1.c") != 0)
+    {
+      puts ("`getvarinmod1' returns wrong value");
+      res = 1;
+    }
+  if (strcmp (getvarinmod2 (), "vismod2.c") != 0)
+    {
+      puts ("`getvarinmod2' returns wrong value");
+      res = 1;
+    }
+
+  /* And a test where a variable definition is intercepted.  */
+  if (protvaritcpt == getvaritcpt1 ())
+    {
+      puts ("`protvaritcpt' in main and mod1 have same address");
+      res = 1;
+    }
+  if (protvaritcpt == getvaritcpt2 ())
+    {
+      puts ("`protvaritcpt' in main and mod2 have same address");
+      res = 1;
+    }
+  if (protvaritcpt != getvaritcpt3 ())
+    {
+      puts ("`protvaritcpt' in main and mod3 have not same address");
+      res = 1;
+    }
+  if (getvaritcpt1 () == getvaritcpt2 ())
+    {
+      puts ("`protvaritcpt' in mod1 and mod2 have same address");
+      res = 1;
+    }
+  if (strcmp (protvaritcpt, "vismod3.c") != 0)
+    {
+      puts ("`protvaritcpt in main has wrong value");
+      res = 1;
+    }
+  if (strcmp (getvaritcpt1 (), "vismod1.c") != 0)
+    {
+      puts ("`getvaritcpt1' returns wrong value");
+      res = 1;
+    }
+  if (strcmp (getvaritcpt2 (), "vismod2.c") != 0)
+    {
+      puts ("`getvaritcpt2' returns wrong value");
+      res = 1;
+    }
+
+  return res;
+}
+
+
+int
+protlocal (void)
+{
+  return 0x1;
+}