hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame elf/tst-dlopen-pie.c

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