Blame elf/tst-dlopen-pie.c

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