|
Packit Service |
82fcde |
/* Test the protected visibility when main is linked with moda and modb
|
|
Packit Service |
82fcde |
in that order:
|
|
Packit Service |
82fcde |
1. Protected symbols, protected1, protected2 and protected3, defined
|
|
Packit Service |
82fcde |
in moda, are used in moda.
|
|
Packit Service |
82fcde |
2. Protected symbol, protected3, defined in modb, are used in modb.
|
|
Packit Service |
82fcde |
3. Symbol, protected1, defined in moda, is also used in main and modb.
|
|
Packit Service |
82fcde |
4. Symbol, protected2, defined in main, is used in main.
|
|
Packit Service |
82fcde |
5. Symbol, protected3, defined in moda, is also used in main.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
Copyright (C) 2015-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* This file must be compiled as PIE to avoid copy relocation when
|
|
Packit Service |
82fcde |
accessing protected symbols defined in shared libaries since copy
|
|
Packit Service |
82fcde |
relocation doesn't work with protected symbols and linker in
|
|
Packit Service |
82fcde |
binutils 2.26 enforces this rule. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <stdlib.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include "tst-protected1mod.h"
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Prototype for our test function. */
|
|
Packit Service |
82fcde |
extern int do_test (void);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int protected2 = -1;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* This defines the `main' function and some more. */
|
|
Packit Service |
82fcde |
#include <support/test-driver.c>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
int
|
|
Packit Service |
82fcde |
do_test (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int res = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the same address for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (&protected1 != protected1a_p ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in main and moda doesn't have same address");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (&protected1 != protected1b_p ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in main and modb doesn't have same address");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the right value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected1 != 3)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in main and moda doesn't have same value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the right value for data defined in executable. */
|
|
Packit Service |
82fcde |
if (protected2 != -1)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected2' in main has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected1' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected1 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected2' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected2 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected2' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the same address for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (&protected3 != protected3a_p ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in main and moda doesn't have same address");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
if (&protected3 == protected3b_p ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in main and modb has same address");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the right value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected3 != 5)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in main and moda doesn't have same value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected3a ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in modb. */
|
|
Packit Service |
82fcde |
if (!check_protected3b ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in modb has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set `protected2' in moda to 30. */
|
|
Packit Service |
82fcde |
set_protected2 (300);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected2' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected2 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected2' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set `protected1' in moda to 30. */
|
|
Packit Service |
82fcde |
set_protected1a (30);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected1' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected1 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the updated value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected1 != 30)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in main doesn't have the updated value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
protected2 = -300;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected2' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected2 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected2' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if data defined in executable is changed. */
|
|
Packit Service |
82fcde |
if (protected2 != -300)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected2' in main is changed");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set `protected1' in modb to 40. */
|
|
Packit Service |
82fcde |
set_protected1b (40);
|
|
Packit Service |
82fcde |
set_expected_protected1 (40);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected1' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected1 ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the updated value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected1 != 40)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected1' in main doesn't have the updated value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set `protected3' in moda to 80. */
|
|
Packit Service |
82fcde |
set_protected3a (80);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected3a ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the updated value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected3 != 80)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in main doesn't have the updated value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in modb. */
|
|
Packit Service |
82fcde |
if (!check_protected3b ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in modb has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Set `protected3' in modb to 100. */
|
|
Packit Service |
82fcde |
set_protected3b (100);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in moda. */
|
|
Packit Service |
82fcde |
if (!check_protected3a ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in moda has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check if we get the updated value for the protected data symbol. */
|
|
Packit Service |
82fcde |
if (protected3 != 80)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in main doesn't have the updated value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Check `protected3' in modb. */
|
|
Packit Service |
82fcde |
if (!check_protected3b ())
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
puts ("`protected3' in modb has the wrong value");
|
|
Packit Service |
82fcde |
res = 1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return res;
|
|
Packit Service |
82fcde |
}
|