Blame elf/tst-protected1b.c

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