Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package nvptx-tools for openSUSE:Factory 
checked in at 2023-07-24 18:26:04
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/nvptx-tools (Old)
 and      /work/SRC/openSUSE:Factory/.nvptx-tools.new.1467 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "nvptx-tools"

Mon Jul 24 18:26:04 2023 rev:7 rq:1099901 version:1.0+git.20230718.bbb6fe6

Changes:
--------
--- /work/SRC/openSUSE:Factory/nvptx-tools/nvptx-tools.changes  2023-03-22 
22:32:00.410605271 +0100
+++ /work/SRC/openSUSE:Factory/.nvptx-tools.new.1467/nvptx-tools.changes        
2023-07-24 18:26:32.926355365 +0200
@@ -1,0 +2,26 @@
+Fri Jul 21 12:00:05 UTC 2023 - [email protected]
+
+- Update to version 1.0+git.20230718.bbb6fe6:
+  * Document "Program Instrumentation: Sanitizers" in 'README-development'
+  * run: Move 'cuModuleGetFunction' for '__main' out of 'compile_file'
+  * run: Plug 'compile_file' memory leaks
+  * run: Localize 'cuda_lib'
+  * as: Localize 'collect_wait'
+  * as: Don't 'unlink (NULL)'
+  * as: Don't use an obstack for 'ptxas' invocation [#1]
+  * ld: Remove unused '#include "obstack.h"' [#1]
+  * ld, nm: Stop 'using namespace std;'
+  * run: For auto '--stack-size', consider free instead of total device memory 
[#8]
+  * ld: Support archives appearing as input files
+  * ld: Don't reject empty archives
+  * ld: Make resolving of '-l'ibraries a separate step
+  * ld: Verify no NUL-separated parts for 'process_refs_defs'
+  * ld: Fix undefined behavior reading objects from archives
+  * ld: Document padding of objects in archives
+  * as: Plug 'alloc_stmt' memory leak
+  * as: Plug 'read_file' memory leak
+  * as: Plug 'tokenize' memory leak
+  * as: Conceptually simplify capture of preamble '.target' directive's 
argument
+  * 'test/GLOBAL_FUNCTION_DECL_f.s': 'f' is '.extern', not '.visible' [#38]
+
+-------------------------------------------------------------------

Old:
----
  nvptx-tools-1.0+git.20230122.93e0090.tar.xz

New:
----
  nvptx-tools-1.0+git.20230718.bbb6fe6.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ nvptx-tools.spec ++++++
--- /var/tmp/diff_new_pack.95ADux/_old  2023-07-24 18:26:33.570359148 +0200
+++ /var/tmp/diff_new_pack.95ADux/_new  2023-07-24 18:26:33.574359172 +0200
@@ -17,7 +17,7 @@
 
 
 Name:           nvptx-tools
-Version:        1.0+git.20230122.93e0090
+Version:        1.0+git.20230718.bbb6fe6
 Release:        0
 Summary:        PTX language tools
 License:        GPL-3.0-or-later

++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.95ADux/_old  2023-07-24 18:26:33.634359525 +0200
+++ /var/tmp/diff_new_pack.95ADux/_new  2023-07-24 18:26:33.638359548 +0200
@@ -1,6 +1,6 @@
 <servicedata>
 <service name="tar_scm">
                 <param 
name="url">https://github.com/MentorEmbedded/nvptx-tools</param>
-              <param 
name="changesrevision">93e00909ceb9cbbc104f0fcba56c0361ffb3ca4b</param></service></servicedata>
+              <param 
name="changesrevision">bbb6fe642c6c50422e2886b3f488fcb776336c46</param></service></servicedata>
 (No newline at EOF)
 

++++++ nvptx-tools-1.0+git.20230122.93e0090.tar.xz -> 
nvptx-tools-1.0+git.20230718.bbb6fe6.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/nvptx-tools-1.0+git.20230122.93e0090/README-development 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/README-development
--- old/nvptx-tools-1.0+git.20230122.93e0090/README-development 1970-01-01 
01:00:00.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/README-development 2023-07-18 
16:13:51.000000000 +0200
@@ -0,0 +1,16 @@
+Program Instrumentation: Sanitizers
+-----------------------------------
+
+    $ ./configure CXXFLAGS='-O0 -ggdb -fsanitize=address -fsanitize=undefined'
+
+This compiles the nvptx-tools proper (but not libiberty) with the specified
+sanitizers enabled.
+
+If the 'run' test cases fail due to:
+
+    nvptx-run: cuInit failed: out of memory (CUDA_ERROR_OUT_OF_MEMORY, 2)
+
+..., per <https://github.com/google/sanitizers/issues/629>
+"asan: problem calling NVIDIA CUDA libraries" run with
+'ASAN_OPTIONS=protect_shadow_gap=false', to override the 'true' default;
+<https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags>.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-as.cc 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-as.cc
--- old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-as.cc        2023-01-22 
23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-as.cc        2023-07-18 
16:13:51.000000000 +0200
@@ -36,9 +36,6 @@
 #include <errno.h>
 #include <assert.h>
 
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
 #define HAVE_DECL_BASENAME 1
 #include <libiberty.h>
 #include <hashtab.h>
@@ -94,7 +91,9 @@
   fprintf (stderr, "\n");
   va_end (ap);
 
-  unlink (outname);
+  if (outname)
+    unlink (outname);
+
   exit (1);
 }
 
@@ -192,8 +191,8 @@
   char const *ptr;
 } Token;
 
-/* Token of the preamble '.target' directive's argument.  */
-static Token *tok_preamble_target_arg;
+/* The preamble '.target' directive's argument.  */
+static char *preamble_target_arg;
 
 /* statement info */
 typedef enum Vis
@@ -507,6 +506,8 @@
     fputs ("\n", out);
 }
 
+static std::list<void *> heaps;
+
 static Stmt *
 alloc_stmt (unsigned vis, Token *tokens, Token *end, symbol *sym)
 {
@@ -517,6 +518,7 @@
     {
       alloc = 1000;
       heap = XNEWVEC (Stmt, alloc);
+      heaps.push_back (heap);
     }
 
   Stmt *stmt = heap++;
@@ -898,10 +900,13 @@
       /* An empty file isn't a valid PTX file.  */
       *verify = 0;
 
+      XDELETEVEC (input);
+
       return;
     }
 
   Token *tok = tokenize (input);
+  Token *tok_to_free = tok;
 
   /* Do minimalistic verification, so that we reliably reject (certain classes
      of) invalid input.  (If available and applicable, 'ptxas' is later used to
@@ -937,7 +942,8 @@
        i++;
       if (tok[i].kind == K_symbol)
        {
-         tok_preamble_target_arg = &tok[i];
+         assert (!preamble_target_arg);
+         preamble_target_arg = xstrndup (tok[i].ptr, tok[i].len);
          i++;
        }
       else
@@ -962,11 +968,22 @@
   write_stmts (out, rev_stmts (fns));
 
   htab_delete (symbol_table);
+
+  while (!heaps.empty ())
+    {
+      void *heap = heaps.front ();
+      XDELETEVEC (heap);
+      heaps.pop_front ();
+    }
+
+  XDELETEVEC (tok_to_free);
+
+  XDELETEVEC (input);
 }
 
 /* Wait for a process to finish, and exit if a nonzero status is found.  */
 
-int
+static int
 collect_wait (const char *prog, struct pex_obj *pex)
 {
   int status;
@@ -1004,11 +1021,11 @@
 
 /* Execute a program, and wait for the reply.  */
 static void
-fork_execute (const char *prog, char *const *argv)
+fork_execute (const char *prog, const char *const *argv)
 {
   if (verbose)
     {
-      for (char *const *arg = argv; *arg; ++arg)
+      for (const char *const *arg = argv; *arg; ++arg)
        {
          if (**arg == '\0')
            fprintf (stderr, " ''");
@@ -1025,8 +1042,9 @@
   int err;
   const char *errmsg;
 
-  errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH, argv[0], argv, NULL,
-                   NULL, &err);
+  errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH,
+                   argv[0], const_cast<char *const *>(argv),
+                   NULL, NULL, &err);
   if (errmsg != NULL)
     {
       if (err != 0)
@@ -1239,12 +1257,11 @@
   if (verify > 0)
     {
       const char *target_arg;
-      char *target_arg_to_free = NULL;
       if (target_arg_force)
        target_arg = target_arg_force;
       else
        {
-         assert (tok_preamble_target_arg);
+         assert (preamble_target_arg);
 
          /* Override the default '--gpu-name' of 'ptxas': its default may not
             be sufficient for what is requested in the '.target' directive in
@@ -1253,9 +1270,7 @@
                 ptxas fatal   : SM version specified by .target is higher than 
default SM version assumed
 
             In this case, use the '.target' we found in the preamble.  */
-         target_arg = target_arg_to_free
-           = xstrndup (tok_preamble_target_arg->ptr,
-                       tok_preamble_target_arg->len);
+         target_arg = preamble_target_arg;
 
          if ((strcmp ("sm_30", target_arg) == 0)
              || (strcmp ("sm_32", target_arg) == 0))
@@ -1283,21 +1298,18 @@
            }
        }
 
-      struct obstack argv_obstack;
-      obstack_init (&argv_obstack);
-      obstack_ptr_grow (&argv_obstack, "ptxas");
-      obstack_ptr_grow (&argv_obstack, "-c");
-      obstack_ptr_grow (&argv_obstack, "-o");
-      obstack_ptr_grow (&argv_obstack, "/dev/null");
-      obstack_ptr_grow (&argv_obstack, outname);
-      obstack_ptr_grow (&argv_obstack, "--gpu-name");
-      obstack_ptr_grow (&argv_obstack, target_arg);
-      obstack_ptr_grow (&argv_obstack, "-O0");
-      obstack_ptr_grow (&argv_obstack, NULL);
-      char *const *new_argv = XOBFINISH (&argv_obstack, char *const *);
+      const char *const new_argv[] = {
+       "ptxas",
+       "-c",
+       "-o",
+       "/dev/null",
+       outname,
+       "--gpu-name",
+       target_arg,
+       "-O0",
+       NULL,
+      };
       fork_execute (new_argv[0], new_argv);
-      obstack_free (&argv_obstack, NULL);
-      free (target_arg_to_free);
     }
   else if (verify < 0)
     {
@@ -1305,5 +1317,7 @@
        fprintf (stderr, "'ptxas' not available.\n");
     }
 
+  free (preamble_target_arg);
+
   return 0;
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-ld.cc 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-ld.cc
--- old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-ld.cc        2023-01-22 
23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-ld.cc        2023-07-18 
16:13:51.000000000 +0200
@@ -24,7 +24,6 @@
 #include <assert.h>
 
 #include "hashtab.h"
-#include "obstack.h"
 #define HAVE_DECL_BASENAME 1
 #include "libiberty.h"
 
@@ -134,8 +133,6 @@
   free (v);
 }
 
-using namespace std;
-
 #define ARMAG  "!<arch>\012"    /* For COFF and a.out archives.  */
 #define SARMAG 8
 #define ARFMAG "`\012"
@@ -173,19 +170,32 @@
       delete[] contents;
     contents = NULL;
   }
-  bool init (FILE *file)
+
+  static bool is_archive (FILE *file)
   {
     char magic[SARMAG];
     if (fread (magic, 1, SARMAG, file) != SARMAG)
       return false;
     if (memcmp (magic, ARMAG, SARMAG) != 0)
       return false;
+    return true;
+  }
+
+  bool init (FILE *file)
+  {
+    if (!is_archive (file))
+      return false;
+
     f = file;
     fseek (f, 0, SEEK_END);
     flen = ftell (f);
     fseek (f, SARMAG, SEEK_SET);
     off = SARMAG;
 
+    if (at_end ())
+      /* Empty archive; valid.  */
+      return true;
+
     struct ar_hdr hdr;
     if (fread (&hdr, sizeof hdr, 1, f) != 1)
       return false;
@@ -218,6 +228,10 @@
     long l = atol (hdr.ar_size);
     if (l <= 0 || l > flen)
       return false;
+    /* <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ar.html>:
+       "Objects in the archive are always an even number of bytes long; files
+       that are an odd number of bytes long are padded with a <newline>,
+       although the size in the header does not reflect this."  */
     size_t read_len = l + (l & 1);
     len = l;
     contents = new char[read_len];
@@ -235,21 +249,20 @@
   size_t get_len () { return len; }
 };
 
-FILE *
-path_open (const char *filename, list<string> &paths)
+static std::string
+path_resolve (const std::string &filename, const std::list<std::string> &paths)
 {
-  for (list<string>::const_iterator iterator = paths.begin(), end = 
paths.end();
+  for (std::list<std::string>::const_iterator iterator = paths.begin(), end = 
paths.end();
        iterator != end;
        ++iterator)
     {
-      string tmp = *iterator;
+      std::string tmp = *iterator;
       tmp += '/';
       tmp += filename;
-      FILE *f = fopen (tmp.c_str (), "r");
-      if (f)
-       return f;
+      if (access (tmp.c_str (), F_OK) == 0)
+       return tmp;
     }
-  return NULL;
+  return "";
 }
 
 static struct symbol_hash_entry *unresolved;
@@ -292,7 +305,7 @@
     }
 }
 
-static void
+static const char *
 process_refs_defs (htab_t symbol_table, file *f, const char *ptx)
 {
   while (*ptx != '\0')
@@ -355,6 +368,8 @@
        }
       ptx++;
     }
+  /* Callers may use this return value to detect NUL-separated parts.  */
+  return ptx + 1;
 }
 
 ATTRIBUTE_NORETURN static void
@@ -385,8 +400,8 @@
 main (int argc, char **argv)
 {
   const char *outname = NULL;
-  list<string> libraries;
-  list<string> libpaths;
+  std::list<std::string> libraries;
+  std::list<std::string> libpaths;
   bool verbose = false;
 
   int o;
@@ -401,7 +416,7 @@
        case 'o':
          if (outname != NULL)
            {
-             cerr << "multiple output files specified\n";
+             std::cerr << "multiple output files specified\n";
              exit (1);
            }
          outname = optarg;
@@ -431,8 +446,6 @@
        }
     }
 
-  libraries.sort ();
-  libraries.unique ();
   libpaths.unique ();
 
   if (outname == NULL)
@@ -442,32 +455,63 @@
     = htab_create (500, hash_string_hash, hash_string_eq, symbol_hash_free);
   /* List of 'file_hash_entry' instances to clean up when we're done with the
      'symbol_table'.  */
-  list<file_hash_entry *> f_to_clean_up;
+  std::list<file_hash_entry *> f_to_clean_up;
 
   define_intrinsics (symbol_table);
   
   FILE *outfile = fopen (outname, "w");
   if (outfile == NULL)
     {
-      cerr << "error opening output file\n";
+      std::cerr << "error opening output file\n";
       exit (1);
     }
-  list<string> inputfiles;
+  std::list<std::string> inputfiles;
   while (optind < argc)
     inputfiles.push_back (argv[optind++]);
 
   int idx = 0;
-  for (list<string>::const_iterator iterator = inputfiles.begin(), end = 
inputfiles.end();
+
+  for (std::list<std::string>::iterator iterator = libraries.begin(), end = 
libraries.end();
+       iterator != end;
+       ++iterator)
+    {
+      const std::string &name = "lib" + *iterator + ".a";
+      if (verbose)
+       std::cerr << "resolving lib " << name << "\n";
+      const std::string &name_resolved = path_resolve (name, libpaths);
+      if (name_resolved.empty ())
+       {
+         std::cerr << "error resolving " << name << "\n";
+         goto error_out;
+       }
+      *iterator = name_resolved;
+    }
+
+  for (std::list<std::string>::const_iterator iterator = inputfiles.begin(), 
end = inputfiles.end();
        iterator != end;
        ++iterator)
     {
-      const string &name = *iterator;
+      const std::string &name = *iterator;
       FILE *f = fopen (name.c_str (), "r");
       if (f == NULL)
        {
-         cerr << "error opening " << name << "\n";
+         std::cerr << "error opening " << name << "\n";
          goto error_out;
        }
+
+      /* Archives appearing here are not resolved via 'libpaths'.  */
+      if (archive::is_archive (f))
+       {
+         /* (Pre-existing problem of) non-standard Unix 'ld' semantics; see
+            <https://github.com/MentorEmbedded/nvptx-tools/issues/41>
+            "ld: non-standard handling of options which refer to files".  */
+         libraries.push_back (name);
+
+         fclose (f);
+         f = NULL;
+         continue;
+       }
+
       fseek (f, 0, SEEK_END);
       off_t len = ftell (f);
       fseek (f, 0, SEEK_SET);
@@ -476,7 +520,7 @@
       buf[len] = '\0';
       if (read_len != len || ferror (f))
        {
-         cerr << "error reading " << name << "\n";
+         std::cerr << "error reading " << name << "\n";
          fclose (f);
          goto error_out;
        }
@@ -485,32 +529,38 @@
       size_t out = fwrite (buf, 1, len, outfile);
       if (out != len)
        {
-         cerr << "error writing to output file\n";
+         std::cerr << "error writing to output file\n";
          goto error_out;
        }
-      process_refs_defs (symbol_table, NULL, buf);
+      const char *buf_ = process_refs_defs (symbol_table, NULL, buf);
+      assert (buf_ == &buf[len + 1]);
       delete[] buf;
       if (verbose)
-       cerr << "Linking " << name << " as " << idx++ << "\n";
+       std::cerr << "Linking " << name << " as " << idx++ << "\n";
       fputc ('\0', outfile);
     }
-  for (list<string>::const_iterator iterator = libraries.begin(), end = 
libraries.end();
+
+  /* This de-duplication is best-effort only; it doesn't consider that the same
+     file may be found via different paths.  */
+  libraries.sort ();
+  libraries.unique ();
+  for (std::list<std::string>::const_iterator iterator = libraries.begin(), 
end = libraries.end();
        iterator != end;
        ++iterator)
     {
-      const string &name = "lib" + *iterator + ".a";
+      const std::string &name = *iterator;
       if (verbose)
-       cerr << "trying lib " << name << "\n";
-      FILE *f = path_open (name.c_str (), libpaths);
+       std::cerr << "trying lib " << name << "\n";
+      FILE *f = fopen (name.c_str (), "r");
       if (f == NULL)
        {
-         cerr << "error opening " << name << "\n";
+         std::cerr << "error opening " << name << "\n";
          goto error_out;
        }
       archive ar;
       if (!ar.init (f))
        {
-         cerr << name << " is not a valid archive\n";
+         std::cerr << name << " is not a valid archive\n";
          fclose (f);
          goto error_out;
        }
@@ -518,15 +568,20 @@
        {
          if (!ar.next_file ())
            {
-             cerr << "error reading from archive " << name << "\n";
+             std::cerr << "error reading from archive " << name << "\n";
              fclose (f);
              goto error_out;
            }
-         const char *p = xstrdup (ar.get_contents ());
+
          size_t len = ar.get_len ();
+         char *p = XNEWVEC (char, len + 1);
+         memcpy (p, ar.get_contents (), len);
+         p[len] = '\0';
+
          file *f = file_hash_new (p, len, name.c_str (), ar.get_name ());
          f_to_clean_up.push_front (f);
-         process_refs_defs (symbol_table, f, p);
+         const char *p_ = process_refs_defs (symbol_table, f, p);
+         assert (p_ == &p[len + 1]);
        }
       fclose (f);
     }
@@ -540,11 +595,11 @@
          struct file_hash_entry *f = e->def;
          if (!f)
            {
-             cerr << "unresolved symbol " << e->key << "\n";
+             std::cerr << "unresolved symbol " << e->key << "\n";
              goto error_out;
            }
          if (verbose)
-           cerr << "Resolving " << e->key << "\n";
+           std::cerr << "Resolving " << e->key << "\n";
          if (!f->pprev)
            {
              f->pprev = &to_add;
@@ -561,14 +616,15 @@
        {
          f->pprev = NULL;
          if (verbose)
-           cerr << "Linking " << f->arname << "::" << f->name << " as " << 
idx++ << "\n";
+           std::cerr << "Linking " << f->arname << "::" << f->name << " as " 
<< idx++ << "\n";
          if (fwrite (f->data, 1, f->len, outfile) != f->len)
            {
-             cerr << "error writing to output file\n";
+             std::cerr << "error writing to output file\n";
              goto error_out;
            }
          fputc ('\0', outfile);
-         process_refs_defs (symbol_table, NULL, f->data);
+         const char *f_data_ = process_refs_defs (symbol_table, NULL, f->data);
+         assert (f_data_ == &f->data[f->len + 1]);
        }
     }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-nm.cc 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-nm.cc
--- old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-nm.cc        2023-01-22 
23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-nm.cc        2023-07-18 
16:13:51.000000000 +0200
@@ -130,8 +130,6 @@
   return (struct symbol_hash_entry *) *e;
 }
 
-using namespace std;
-
 static const char *
 process_refs_defs (htab_t symbol_table_global, htab_t symbol_table_local, 
const char *ptx)
 {
@@ -203,6 +201,7 @@
        }
       ptx++;
     }
+  /* Callers may use this return value to detect NUL-separated parts.  */
   return ptx + 1;
 }
 
@@ -230,7 +229,7 @@
       /* No-op.  */
       break;
     default:
-      cerr << f << ": invalid output format\n";
+      std::cerr << f << ": invalid output format\n";
       usage (stderr, 1);
     }
 }
@@ -385,10 +384,10 @@
 }
 
 static void
-display_rel_file (list<htab_t> &symbol_tables, const string &name)
+display_rel_file (std::list<htab_t> &symbol_tables, const std::string &name)
 {
   size_t symcount = 0;
-  for (list<htab_t>::iterator it = symbol_tables.begin ();
+  for (std::list<htab_t>::iterator it = symbol_tables.begin ();
        it != symbol_tables.end();
        ++it)
     symcount += htab_elements (*it);
@@ -404,7 +403,7 @@
   if (symcount == 0)
     {
       if (!quiet)
-       cerr << name << ": no symbols\n";
+       std::cerr << name << ": no symbols\n";
       return;
     }
 #endif
@@ -412,7 +411,7 @@
   symbol_hash_entry **minisyms = XNEWVEC (symbol_hash_entry *, symcount);
   {
     symbol_hash_entry **minisym = minisyms;
-    for (list<htab_t>::iterator it = symbol_tables.begin ();
+    for (std::list<htab_t>::iterator it = symbol_tables.begin ();
         it != symbol_tables.end();
         ++it)
       htab_traverse_noresize (*it, symbol_table_into_array, &minisym);
@@ -567,7 +566,7 @@
        }
     }
 
-  list<string> inputfiles;
+  std::list<std::string> inputfiles;
   while (optind < argc)
     inputfiles.push_back (argv[optind++]);
   if (!inputfiles.size ())
@@ -575,15 +574,15 @@
   if (inputfiles.size () > 1)
     filename_per_file = 1;
 
-  for (list<string>::const_iterator iterator = inputfiles.begin(), end = 
inputfiles.end();
+  for (std::list<std::string>::const_iterator iterator = inputfiles.begin(), 
end = inputfiles.end();
        iterator != end;
        ++iterator)
     {
-      const string &name = *iterator;
+      const std::string &name = *iterator;
       FILE *f = fopen (name.c_str (), "r");
       if (f == NULL)
        {
-         cerr << "error opening " << name << "\n";
+         std::cerr << "error opening " << name << "\n";
          goto error_out;
        }
       fseek (f, 0, SEEK_END);
@@ -594,7 +593,7 @@
       buf[len] = '\0';
       if (read_len != len || ferror (f))
        {
-         cerr << "error reading " << name << "\n";
+         std::cerr << "error reading " << name << "\n";
          fclose (f);
          goto error_out;
        }
@@ -604,7 +603,7 @@
       /* Applies to the whole file.  */
       set_print_width (buf);
 
-      list<htab_t> symbol_tables;
+      std::list<htab_t> symbol_tables;
       htab_t symbol_table_global
        = htab_create (500, hash_string_hash, hash_string_eq, symbol_hash_free);
       symbol_tables.push_back (symbol_table_global);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-run-cuda-lib.def 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-run-cuda-lib.def
--- old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-run-cuda-lib.def     
2023-01-22 23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-run-cuda-lib.def     
2023-07-18 16:13:51.000000000 +0200
@@ -3,7 +3,6 @@
 CUDA_ONE_CALL (cuCtxSetLimit)
 CUDA_ONE_CALL (cuDeviceGet)
 CUDA_ONE_CALL (cuDeviceGetAttribute)
-CUDA_ONE_CALL (cuDeviceTotalMem)
 CUDA_ONE_CALL_MAYBE_NULL (cuGetErrorName)
 CUDA_ONE_CALL_MAYBE_NULL (cuGetErrorString)
 CUDA_ONE_CALL (cuInit)
@@ -11,10 +10,12 @@
 CUDA_ONE_CALL (cuLinkAddData)
 CUDA_ONE_CALL (cuLinkComplete)
 CUDA_ONE_CALL (cuLinkCreate)
+CUDA_ONE_CALL (cuLinkDestroy)
 CUDA_ONE_CALL (cuMemAlloc)
 CUDA_ONE_CALL (cuMemcpyDtoH)
 CUDA_ONE_CALL (cuMemcpyHtoD)
 CUDA_ONE_CALL (cuMemFree)
+CUDA_ONE_CALL (cuMemGetInfo)
 CUDA_ONE_CALL (cuModuleGetFunction)
 CUDA_ONE_CALL (cuModuleLoadData)
 CUDA_ONE_CALL (cuModuleUnload)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-run.cc 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-run.cc
--- old/nvptx-tools-1.0+git.20230122.93e0090/nvptx-run.cc       2023-01-22 
23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/nvptx-run.cc       2023-07-18 
16:13:51.000000000 +0200
@@ -42,7 +42,7 @@
 #ifndef NVPTX_RUN_LINK_LIBCUDA
 # include <dlfcn.h>
 
-struct cuda_lib_s {
+static struct cuda_lib_s {
 
 # define CUDA_ONE_CALL(call)                   \
   __typeof (::call) *call;
@@ -137,7 +137,7 @@
 static size_t jitopt_lineinfo, jitopt_debuginfo, jitopt_optimize = 4;
 
 static void
-compile_file (FILE *f, CUmodule *phModule, CUfunction *phKernel)
+compile_file (FILE *f, CUmodule *phModule)
 {
   CUresult r;
    
@@ -178,7 +178,7 @@
       sprintf (namebuf, "input file %d at offset %d", count++, off);
       r = CUDA_CALL_NOCHECK (cuLinkAddData, linkstate,
                             CU_JIT_INPUT_PTX, program + off, l + 1,
-                            strdup (namebuf), 0, 0, 0);
+                            namebuf, 0, 0, 0);
       if (r != CUDA_SUCCESS)
        {
 #if 0
@@ -193,6 +193,9 @@
        off++;
     }
 
+  delete[] program;
+  program = NULL;
+
   void *linkout;
   r = CUDA_CALL_NOCHECK (cuLinkComplete, linkstate, &linkout, NULL);
   if (r != CUDA_SUCCESS)
@@ -204,8 +207,8 @@
   r = CUDA_CALL_NOCHECK (cuModuleLoadData, phModule, linkout);
   fatal_unless_success (r, "cuModuleLoadData failed");
 
-  r = CUDA_CALL_NOCHECK (cuModuleGetFunction, phKernel, *phModule, "__main");
-  fatal_unless_success (r, "could not find kernel __main");
+  r = CUDA_CALL_NOCHECK (cuLinkDestroy, linkstate);
+  fatal_unless_success (r, "cuLinkDestroy failed");
 }
 
 ATTRIBUTE_NORETURN static void
@@ -371,8 +374,12 @@
                             dev);
       fatal_unless_success (r, "could not get max threads per SM count");
       size_t mem;
-      r = CUDA_CALL_NOCHECK (cuDeviceTotalMem, &mem, dev);
-      fatal_unless_success (r, "could not get available memory");
+      {
+       size_t mem_free, mem_total;
+       r = CUDA_CALL_NOCHECK (cuMemGetInfo, &mem_free, &mem_total);
+       fatal_unless_success (r, "could not get free and total memory");
+       mem = mem_free;
+      }
       /* Subtract heap size and a 128 MiB extra.  */
       mem -= heap_size + 128 * 1024 * 1024;
       mem /= sm_count * thread_max;
@@ -388,12 +395,15 @@
   fatal_unless_success (r, "could not set heap limit");
 
   CUmodule hModule = 0;
-  CUfunction hKernel = 0;
-  compile_file (f, &hModule, &hKernel);
+  compile_file (f, &hModule);
 
   fclose (f);
   f = NULL;
 
+  CUfunction hKernel = 0;
+  r = CUDA_CALL_NOCHECK (cuModuleGetFunction, &hKernel, hModule, "__main");
+  fatal_unless_success (r, "could not find kernel __main");
+
   void *args[] = { &d_retval, &d_argc, &d_argv };
     
   r = CUDA_CALL_NOCHECK (cuLaunchKernel,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/nvptx-tools-1.0+git.20230122.93e0090/test/GLOBAL_FUNCTION_DECL_f.s 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/GLOBAL_FUNCTION_DECL_f.s
--- old/nvptx-tools-1.0+git.20230122.93e0090/test/GLOBAL_FUNCTION_DECL_f.s      
2023-01-22 23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/GLOBAL_FUNCTION_DECL_f.s      
2023-07-18 16:13:51.000000000 +0200
@@ -5,4 +5,4 @@
 // END PREAMBLE
 
 // BEGIN GLOBAL FUNCTION DECL: f
-.visible .func (.param.u32 %value_out) f (.param.u32 %in_ar0, .param.u32 
%in_ar1);
+.extern .func (.param.u32 %value_out) f (.param.u32 %in_ar0, .param.u32 
%in_ar1);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/nvptx-tools-1.0+git.20230122.93e0090/test/ld/empty-2.test 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/ld/empty-2.test
--- old/nvptx-tools-1.0+git.20230122.93e0090/test/ld/empty-2.test       
1970-01-01 01:00:00.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/ld/empty-2.test       
2023-07-18 16:13:51.000000000 +0200
@@ -0,0 +1,56 @@
+Verify that an empty archive isn't rejected.
+
+(Based on 'search-1.test'.)
+
+
+RUN: rm -rf %t
+RUN: mkdir -p %t
+
+
+Assemble.
+
+RUN: mkdir %t/o
+
+RUN: %target_as_cmd -o %t/o/GLOBAL_FUNCTION_DECL_f.o 
%S/../GLOBAL_FUNCTION_DECL_f.s
+
+RUN: %target_as_cmd -o %t/o/GLOBAL_FUNCTION_DEF_f.o 
%S/../GLOBAL_FUNCTION_DEF_f.s
+
+
+Archive.
+
+RUN: mkdir %t/a
+
+RUN: %target_ar_cmd rcs %t/a/libGLOBAL_FUNCTION_f.a 
%t/o/GLOBAL_FUNCTION_DEF_f.o
+
+Create empty archive.
+
+RUN: %target_ar_cmd q %t/a/libempty.a
+
+
+Link.
+
+RUN: rm -f %t.nvptx.golden
+RUN: %target_ld_cmd -o %t.nvptx.golden %t/o/GLOBAL_FUNCTION_DECL_f.o 
%t/o/GLOBAL_FUNCTION_DEF_f.o > %t.stdout 2> %t.stderr
+RUN: ! test -s %t.stdout
+RUN: ! test -s %t.stderr
+
+
+Test.
+
+RUN: rm -f %t.nvptx
+RUN: %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o -L%t/a -lempty 
-lGLOBAL_FUNCTION_f -lempty > %t.stdout 2> %t.stderr
+RUN: cmp %t.nvptx.golden %t.nvptx
+RUN: ! test -s %t.stdout
+RUN: ! test -s %t.stderr
+
+RUN: rm -f %t.nvptx
+RUN: %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o -L%t/a 
%t/a/libempty.a -lGLOBAL_FUNCTION_f %t/a/libempty.a > %t.stdout 2> %t.stderr
+RUN: cmp %t.nvptx.golden %t.nvptx
+RUN: ! test -s %t.stdout
+RUN: ! test -s %t.stderr
+
+RUN: rm -f %t.nvptx
+RUN: %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o -L%t/a -lempty 
-lGLOBAL_FUNCTION_f %t/a/libempty.a > %t.stdout 2> %t.stderr
+RUN: cmp %t.nvptx.golden %t.nvptx
+RUN: ! test -s %t.stdout
+RUN: ! test -s %t.stderr
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/nvptx-tools-1.0+git.20230122.93e0090/test/ld/search-1.test 
new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/ld/search-1.test
--- old/nvptx-tools-1.0+git.20230122.93e0090/test/ld/search-1.test      
2023-01-22 23:42:12.000000000 +0100
+++ new/nvptx-tools-1.0+git.20230718.bbb6fe6/test/ld/search-1.test      
2023-07-18 16:13:51.000000000 +0200
@@ -35,7 +35,11 @@
 RUN: ! test -s %t.stdout
 RUN: ! test -s %t.stderr
 
-TODO Not testing with linker input file '%t/a/libGLOBAL_FUNCTION_f.a', as we 
don't support that yet.
+RUN: rm -f %t.nvptx
+RUN: %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o 
%t/a/libGLOBAL_FUNCTION_f.a > %t.stdout 2> %t.stderr
+RUN: cmp %t.nvptx.golden %t.nvptx
+RUN: ! test -s %t.stdout
+RUN: ! test -s %t.stderr
 
 RUN: rm -f %t.nvptx
 RUN: %target_ld_cmd -o %t.nvptx -L%t/o ./GLOBAL_FUNCTION_DECL_f.o 
./GLOBAL_FUNCTION_DEF_f.o > %t.stdout 2> %t.stderr; r=$?; [ x"$r" = x1 ]
@@ -67,14 +71,14 @@
 RUN: %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o 
-lGLOBAL_FUNCTION_f > %t.stdout 2> %t.stderr; r=$?; [ x"$r" = x1 ]
 RUN: ! test -f %t.nvptx
 RUN: ! test -s %t.stdout
-RUN: echo 'error opening libGLOBAL_FUNCTION_f.a' > %t.stderr.golden
+RUN: echo 'error resolving libGLOBAL_FUNCTION_f.a' > %t.stderr.golden
 RUN: cmp %t.stderr.golden %t.stderr
 
 RUN: rm -f %t.nvptx
 RUN: ( cd %t/a/ && %target_ld_cmd -o %t.nvptx %t/o/GLOBAL_FUNCTION_DECL_f.o 
-lGLOBAL_FUNCTION_f > %t.stdout 2> %t.stderr ); [ x"$r" = x1 ]
 RUN: ! test -f %t.nvptx
 RUN: ! test -s %t.stdout
-RUN: echo 'error opening libGLOBAL_FUNCTION_f.a' > %t.stderr.golden
+RUN: echo 'error resolving libGLOBAL_FUNCTION_f.a' > %t.stderr.golden
 RUN: cmp %t.stderr.golden %t.stderr
 
 RUN: rm -f %t.nvptx

Reply via email to