2020-01-01 08:14:33 +08:00
|
|
|
/* Copyright (C) 2000-2020 Free Software Foundation, Inc.
|
2000-05-24 02:12:52 +08:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 12:58:11 +08:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-05-24 02:12:52 +08:00
|
|
|
|
|
|
|
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
|
2001-07-06 12:58:11 +08:00
|
|
|
Lesser General Public License for more details.
|
2000-05-24 02:12:52 +08:00
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2000-05-24 02:12:52 +08:00
|
|
|
|
2015-02-28 05:56:44 +08:00
|
|
|
/* This file must be compiled as PIE to avoid copy relocation when
|
|
|
|
accessing protected symbols defined in shared libaries since copy
|
|
|
|
relocation doesn't work with protected symbols and linker in
|
|
|
|
binutils 2.26 enforces this rule. */
|
|
|
|
|
2000-05-24 02:12:52 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-12-18 01:09:01 +08:00
|
|
|
#include "vismod.h"
|
|
|
|
|
2000-05-28 00:51:52 +08:00
|
|
|
/* Prototype for our test function. */
|
|
|
|
extern int do_test (void);
|
|
|
|
|
|
|
|
|
|
|
|
/* This defines the `main' function and some more. */
|
2017-04-05 21:34:39 +08:00
|
|
|
#include <support/test-driver.c>
|
2000-05-28 00:51:52 +08:00
|
|
|
|
2000-05-24 02:12:52 +08:00
|
|
|
|
|
|
|
/* Prototypes for local functions. */
|
|
|
|
extern int protlocal (void);
|
|
|
|
|
|
|
|
const char *protvarlocal = __FILE__;
|
|
|
|
extern const char *protvarinmod;
|
|
|
|
extern const char *protvaritcpt;
|
|
|
|
|
|
|
|
int
|
2000-05-28 00:51:52 +08:00
|
|
|
do_test (void)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
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 ())
|
|
|
|
{
|
2003-03-29 11:46:37 +08:00
|
|
|
printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
|
|
|
|
protinmod, getinmod1 ());
|
2000-05-24 02:12:52 +08:00
|
|
|
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 ())
|
|
|
|
{
|
2003-03-29 11:46:37 +08:00
|
|
|
printf ("&protitcpt in main (%p) != &protitcpt in mod3 (%p)\n",
|
|
|
|
&protitcpt, getitcpt3 ());
|
2000-05-24 02:12:52 +08:00
|
|
|
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. */
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvarlocal == getvarlocal1 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`protvarlocal' in main and mod1 have same address");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvarlocal == getvarlocal2 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvarlocal1' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvarlocal2' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now the case where there is no local definition. */
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvarinmod != getvarinmod1 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
2003-03-29 11:46:37 +08:00
|
|
|
printf ("&protvarinmod in main (%p) != &protitcpt in mod1 (%p)\n",
|
|
|
|
&protvarinmod, getvarinmod1 ());
|
2003-03-29 14:49:46 +08:00
|
|
|
// XXX Possibly enable once fixed.
|
|
|
|
// res = 1;
|
2000-05-24 02:12:52 +08:00
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvarinmod == getvarinmod2 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`protvarinmod' in main and mod2 have same address");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvarinmod1' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvarinmod2' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And a test where a variable definition is intercepted. */
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvaritcpt == getvaritcpt1 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`protvaritcpt' in main and mod1 have same address");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvaritcpt == getvaritcpt2 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`protvaritcpt' in main and mod2 have same address");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (&protvaritcpt != getvaritcpt3 ())
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
2003-03-29 11:46:37 +08:00
|
|
|
printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
|
|
|
|
&protvaritcpt, getvaritcpt3 ());
|
2003-03-29 14:49:46 +08:00
|
|
|
// XXX Possibly enable once fixed.
|
|
|
|
// res = 1;
|
2000-05-24 02:12:52 +08:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvaritcpt1' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
2003-03-29 11:46:37 +08:00
|
|
|
if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
|
2000-05-24 02:12:52 +08:00
|
|
|
{
|
|
|
|
puts ("`getvaritcpt2' returns wrong value");
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
protlocal (void)
|
|
|
|
{
|
|
|
|
return 0x1;
|
|
|
|
}
|