Add some relocation overflow checks for x86_64.
[deliverable/binutils-gdb.git] / gold / testsuite / plugin_test.c
index 79ae44e13ac3c7604ceee8e89ca538c4441b013e..bf30d41c269de9b9b077f036456eb3323a2c711b 100644 (file)
@@ -1,6 +1,6 @@
 /* test_plugin.c -- simple linker plugin test
 
-   Copyright (C) 2008-2014 Free Software Foundation, Inc.
+   Copyright (C) 2008-2016 Free Software Foundation, Inc.
    Written by Cary Coutant <ccoutant@google.com>.
 
    This file is part of gold.
@@ -263,15 +263,35 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed)
   int vis;
   int is_comdat;
   int i;
+  int irfile_was_opened = 0;
+  char syms_name[80];
 
   (*message)(LDPL_INFO,
              "%s: claim file hook called (offset = %ld, size = %ld)",
              file->name, (long)file->offset, (long)file->filesize);
 
+  /* Look for matching syms file for an archive member.  */
+  if (file->offset == 0)
+    snprintf(syms_name, sizeof(syms_name), "%s.syms", file->name);
+  else
+    snprintf(syms_name, sizeof(syms_name), "%s-%d.syms",
+            file->name, (int)file->offset);
+  irfile = fopen(syms_name, "r");
+  if (irfile != NULL)
+    {
+      irfile_was_opened = 1;
+      end_offset = 1 << 20;
+    }
+
+  /* Otherwise, see if the file itself is a syms file.  */
+  if (!irfile_was_opened)
+    {
+      irfile = fdopen(file->fd, "r");
+      (void)fseek(irfile, file->offset, SEEK_SET);
+      end_offset = file->offset + file->filesize;
+    }
+
   /* Look for the beginning of output from readelf -s.  */
-  irfile = fdopen(file->fd, "r");
-  (void)fseek(irfile, file->offset, SEEK_SET);
-  end_offset = file->offset + file->filesize;
   len = fread(buf, 1, 13, irfile);
   if (len < 13 || strncmp(buf, "\nSymbol table", 13) != 0)
     return LDPS_OK;
@@ -378,6 +398,8 @@ claim_file_hook (const struct ld_plugin_input_file* file, int* claimed)
     (*add_symbols)(file->handle, nsyms, syms);
 
   *claimed = 1;
+  if (irfile_was_opened)
+    fclose(irfile);
   return LDPS_OK;
 }
 
@@ -474,12 +496,31 @@ all_symbols_read_hook(void)
        claimed_file != NULL;
        claimed_file = claimed_file->next)
     {
+      int irfile_was_opened = 0;
+      char syms_name[80];
+
       (*get_input_file) (claimed_file->handle, &file);
 
+      if (file.offset == 0)
+       snprintf(syms_name, sizeof(syms_name), "%s.syms", file.name);
+      else
+       snprintf(syms_name, sizeof(syms_name), "%s-%d.syms",
+                file.name, (int)file.offset);
+      irfile = fopen(syms_name, "r");
+      if (irfile != NULL)
+       {
+         irfile_was_opened = 1;
+         end_offset = 1 << 20;
+       }
+
+      if (!irfile_was_opened)
+       {
+         irfile = fdopen(file.fd, "r");
+         (void)fseek(irfile, file.offset, SEEK_SET);
+         end_offset = file.offset + file.filesize;
+       }
+
       /* Look for the beginning of output from readelf -s.  */
-      irfile = fdopen(file.fd, "r");
-      (void)fseek(irfile, file.offset, SEEK_SET);
-      end_offset = file.offset + file.filesize;
       len = fread(buf, 1, 13, irfile);
       if (len < 13 || strncmp(buf, "\nSymbol table", 13) != 0)
         {
@@ -509,6 +550,9 @@ all_symbols_read_hook(void)
             }
         }
 
+      if (irfile_was_opened)
+       fclose(irfile);
+
       (*release_input_file) (claimed_file->handle);
 
       if (filename == NULL)
This page took 0.028861 seconds and 4 git commands to generate.