Blame elf/tst-dlopen-pie.c

Packit Bot aa5b80
/* dlopen test for PIE objects.
Packit Bot aa5b80
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Bot aa5b80
   This file is part of the GNU C Library.
Packit Bot aa5b80
Packit Bot aa5b80
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot aa5b80
   modify it under the terms of the GNU Lesser General Public
Packit Bot aa5b80
   License as published by the Free Software Foundation; either
Packit Bot aa5b80
   version 2.1 of the License, or (at your option) any later version.
Packit Bot aa5b80
Packit Bot aa5b80
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot aa5b80
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot aa5b80
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot aa5b80
   Lesser General Public License for more details.
Packit Bot aa5b80
Packit Bot aa5b80
   You should have received a copy of the GNU Lesser General Public
Packit Bot aa5b80
   License along with the GNU C Library; if not, see
Packit Bot aa5b80
   <http://www.gnu.org/licenses/>.  */
Packit Bot aa5b80
Packit Bot aa5b80
/* This test attempts to open the (otherwise unrelated) PIE test
Packit Bot aa5b80
   program elf/tst-pie1 and expects the attempt to fail.  */
Packit Bot aa5b80
Packit Bot aa5b80
#include <dlfcn.h>
Packit Bot aa5b80
#include <stddef.h>
Packit Bot aa5b80
#include <string.h>
Packit Bot aa5b80
#include <support/check.h>
Packit Bot aa5b80
#include <support/support.h>
Packit Bot aa5b80
Packit Bot aa5b80
static void
Packit Bot aa5b80
test_mode (int mode)
Packit Bot aa5b80
{
Packit Bot aa5b80
  char *pie_path = xasprintf ("%s/elf/tst-pie1", support_objdir_root);
Packit Bot aa5b80
  if (dlopen (pie_path, mode) != NULL)
Packit Bot aa5b80
    FAIL_EXIT1 ("dlopen succeeded unexpectedly (%d)", mode);
Packit Bot aa5b80
  const char *message = dlerror ();
Packit Bot aa5b80
  const char *expected
Packit Bot aa5b80
    = "cannot dynamically load position-independent executable";
Packit Bot aa5b80
  if (strstr (message, expected) == NULL)
Packit Bot aa5b80
    FAIL_EXIT1 ("unexpected error message (mode %d): %s", mode, message);
Packit Bot aa5b80
}
Packit Bot aa5b80
Packit Bot aa5b80
static int
Packit Bot aa5b80
do_test (void)
Packit Bot aa5b80
{
Packit Bot aa5b80
  test_mode (RTLD_LAZY);
Packit Bot aa5b80
  test_mode (RTLD_NOW);
Packit Bot aa5b80
  return 0;
Packit Bot aa5b80
}
Packit Bot aa5b80
Packit Bot aa5b80
#include <support/test-driver.c>