View | Details | Raw Unified | Return to bug 20876 | Differences between
and this patch

Collapse All | Expand All

(-)a/bfd/bfd-in2.h (+2 lines)
Lines 1121-1126 struct bfd_section *bfd_create_gnu_debuglink_section Link Here
1121
bfd_boolean bfd_fill_in_gnu_debuglink_section
1121
bfd_boolean bfd_fill_in_gnu_debuglink_section
1122
   (bfd *abfd, struct bfd_section *sect, const char *filename);
1122
   (bfd *abfd, struct bfd_section *sect, const char *filename);
1123
1123
1124
char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir);
1125
1124
/* Extracted from libbfd.c.  */
1126
/* Extracted from libbfd.c.  */
1125
1127
1126
/* Byte swapping macros for user section data.  */
1128
/* Byte swapping macros for user section data.  */
(-)a/bfd/dwarf2.c (-1 / +5 lines)
Lines 3921-3927 _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd, Link Here
3921
  msec = find_debug_info (debug_bfd, debug_sections, NULL);
3921
  msec = find_debug_info (debug_bfd, debug_sections, NULL);
3922
  if (msec == NULL && abfd == debug_bfd)
3922
  if (msec == NULL && abfd == debug_bfd)
3923
    {
3923
    {
3924
      char * debug_filename = bfd_follow_gnu_debuglink (abfd, DEBUGDIR);
3924
      char * debug_filename;
3925
3926
      debug_filename = bfd_follow_build_id_debuglink (abfd, DEBUGDIR);
3927
      if (debug_filename == NULL)
3928
	debug_filename = bfd_follow_gnu_debuglink (abfd, DEBUGDIR);
3925
3929
3926
      if (debug_filename == NULL)
3930
      if (debug_filename == NULL)
3927
	/* No dwarf2 info, and no gnu_debuglink to follow.
3931
	/* No dwarf2 info, and no gnu_debuglink to follow.
(-)a/bfd/opncls.c (-39 / +334 lines)
Lines 25-30 Link Here
25
#include "objalloc.h"
25
#include "objalloc.h"
26
#include "libbfd.h"
26
#include "libbfd.h"
27
#include "libiberty.h"
27
#include "libiberty.h"
28
#include "elf-bfd.h"
28
29
29
#ifndef S_IXUSR
30
#ifndef S_IXUSR
30
#define S_IXUSR 0100	/* Execute by owner.  */
31
#define S_IXUSR 0100	/* Execute by owner.  */
Lines 1305-1311 INTERNAL_FUNCTION Link Here
1305
1306
1306
SYNOPSIS
1307
SYNOPSIS
1307
	bfd_boolean separate_alt_debug_file_exists
1308
	bfd_boolean separate_alt_debug_file_exists
1308
	  (char *name, unsigned long crc32);
1309
	  (char *name, unsigned long buildid);
1309
1310
1310
DESCRIPTION
1311
DESCRIPTION
1311
	Checks to see if @var{name} is a file and if its BuildID
1312
	Checks to see if @var{name} is a file and if its BuildID
Lines 1336-1352 INTERNAL_FUNCTION Link Here
1336
	find_separate_debug_file
1337
	find_separate_debug_file
1337
1338
1338
SYNOPSIS
1339
SYNOPSIS
1339
	char *find_separate_debug_file (bfd *abfd);
1340
	char *find_separate_debug_file
1341
	  (bfd *abfd, const char *dir, bfd_boolean include_dirs,
1342
	   get_func_type get, check_func_type check);
1340
1343
1341
DESCRIPTION
1344
DESCRIPTION
1342
	Searches @var{abfd} for a section called @var{section_name} which
1345
	Searches for a debug information file corresponding to @var{abfd}.
1343
	is expected to contain a reference to a file containing separate
1346
	The name of the separate debug info file is returned by the @var{get}
1344
	debugging information.  The function scans various locations in
1347
	function.  This function scans various fixed locations in the
1345
	the filesystem, including the file tree rooted at
1348
	filesystem, including the file tree rooted at @var{dir}.  If the
1346
	@var{debug_file_directory}, and returns the first matching
1349
	@var{include_dirs} parameter is true then the directory components of
1347
	filename that it finds.  If @var{check_crc} is TRUE then the
1350
	@var{abfd}'s filename will be included in the searched locations.
1348
	contents of the file must also match the CRC value contained in
1351
1349
	@var{section_name}.  Returns NULL if no valid file could be found.
1352
	Returns the filename of the first file to be found which receives a
1353
	TRUE result from the @var{check} function.  Returns NULL if no valid
1354
	file could be found.
1350
*/
1355
*/
1351
1356
1352
typedef char *      (* get_func_type) (bfd *, unsigned long *);
1357
typedef char *      (* get_func_type) (bfd *, unsigned long *);
Lines 1355-1360 typedef bfd_boolean (* check_func_type) (const char *, const unsigned long); Link Here
1355
static char *
1360
static char *
1356
find_separate_debug_file (bfd *           abfd,
1361
find_separate_debug_file (bfd *           abfd,
1357
			  const char *    debug_file_directory,
1362
			  const char *    debug_file_directory,
1363
			  bfd_boolean     include_dirs,
1358
			  get_func_type   get_func,
1364
			  get_func_type   get_func,
1359
			  check_func_type check_func)
1365
			  check_func_type check_func)
1360
{
1366
{
Lines 1389-1406 find_separate_debug_file (bfd * abfd, Link Here
1389
      return NULL;
1395
      return NULL;
1390
    }
1396
    }
1391
1397
1392
  for (dirlen = strlen (abfd->filename); dirlen > 0; dirlen--)
1398
  if (include_dirs)
1393
    if (IS_DIR_SEPARATOR (abfd->filename[dirlen - 1]))
1399
    {
1394
      break;
1400
      for (dirlen = strlen (abfd->filename); dirlen > 0; dirlen--)
1401
	if (IS_DIR_SEPARATOR (abfd->filename[dirlen - 1]))
1402
	  break;
1395
1403
1396
  dir = (char *) bfd_malloc (dirlen + 1);
1404
      dir = (char *) bfd_malloc (dirlen + 1);
1397
  if (dir == NULL)
1405
      if (dir == NULL)
1406
	{
1407
	  free (base);
1408
	  return NULL;
1409
	}
1410
      memcpy (dir, abfd->filename, dirlen);
1411
      dir[dirlen] = '\0';
1412
    }
1413
  else
1398
    {
1414
    {
1399
      free (base);
1415
      dir = (char *) bfd_malloc (1);
1400
      return NULL;
1416
      * dir = 0;
1417
      dirlen = 0;
1401
    }
1418
    }
1402
  memcpy (dir, abfd->filename, dirlen);
1403
  dir[dirlen] = '\0';
1404
1419
1405
  /* Compute the canonical name of the bfd object with all symbolic links
1420
  /* Compute the canonical name of the bfd object with all symbolic links
1406
     resolved, for use in the global debugfile directory.  */
1421
     resolved, for use in the global debugfile directory.  */
Lines 1410-1447 find_separate_debug_file (bfd * abfd, Link Here
1410
      break;
1425
      break;
1411
  canon_dir[canon_dirlen] = '\0';
1426
  canon_dir[canon_dirlen] = '\0';
1412
1427
1428
#ifndef EXTRA_DEBUG_ROOT1
1429
#define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
1430
#endif
1431
#ifndef EXTRA_DEBUG_ROOT2
1432
#define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
1433
#endif  
1434
1413
  debugfile = (char *)
1435
  debugfile = (char *)
1414
      bfd_malloc (strlen (debug_file_directory) + 1
1436
      bfd_malloc (strlen (debug_file_directory) + 1
1415
                  + (canon_dirlen > dirlen ? canon_dirlen : dirlen)
1437
                  + (canon_dirlen > dirlen ? canon_dirlen : dirlen)
1416
                  + strlen (".debug/")
1438
                  + strlen (".debug/")
1439
#ifdef EXTRA_DEBUG_ROOT1
1440
		  + strlen (EXTRA_DEBUG_ROOT1)
1441
#endif
1442
#ifdef EXTRA_DEBUG_ROOT2
1443
		  + strlen (EXTRA_DEBUG_ROOT2)
1444
#endif
1417
                  + strlen (base)
1445
                  + strlen (base)
1418
                  + 1);
1446
                  + 1);
1419
  if (debugfile == NULL)
1447
  if (debugfile == NULL)
1420
    goto found; /* Actually this returns NULL.  */
1448
    goto found; /* Actually this returns NULL.  */
1421
1449
1422
  /* First try in the same directory as the original file:  */
1450
  /* First try in the same directory as the original file.
1423
  strcpy (debugfile, dir);
1424
  strcat (debugfile, base);
1425
1451
1452
     FIXME: Strictly speaking if we are using the build-id method,
1453
     (ie include_dirs == FALSE) then we should only check absolute
1454
     paths, not relative ones like this one (and the next one).
1455
     The check is left in however as this allows the binutils
1456
     testsuite to exercise this feature without having to install
1457
     a file into the root filesystem.  (See binutils/testsuite/
1458
     binutils-all/objdump.exp for the test).  */
1459
  sprintf (debugfile, "%s%s", dir, base);
1426
  if (check_func (debugfile, crc32))
1460
  if (check_func (debugfile, crc32))
1427
    goto found;
1461
    goto found;
1428
1462
1429
  /* Then try in a subdirectory called .debug.  */
1463
  /* Then try in a subdirectory called .debug.  */
1430
  strcpy (debugfile, dir);
1464
  sprintf (debugfile, "%s.debug/%s", dir, base);
1431
  strcat (debugfile, ".debug/");
1465
  if (check_func (debugfile, crc32))
1432
  strcat (debugfile, base);
1466
    goto found;
1433
1467
1468
#ifdef EXTRA_DEBUG_ROOT1
1469
  /* Try the first extra debug file root.  */
1470
  sprintf (debugfile, "%s%s%s", EXTRA_DEBUG_ROOT1,
1471
	   include_dirs ? canon_dir : "/", base);
1434
  if (check_func (debugfile, crc32))
1472
  if (check_func (debugfile, crc32))
1435
    goto found;
1473
    goto found;
1474
#endif
1436
1475
1476
#ifdef EXTRA_DEBUG_ROOT2
1477
  /* Try the second extra debug file root.  */
1478
  sprintf (debugfile, "%s%s%s", EXTRA_DEBUG_ROOT2,
1479
	   include_dirs ? canon_dir : "/", base);
1480
  if (check_func (debugfile, crc32))
1481
    goto found;
1482
#endif
1483
  
1437
  /* Then try in the global debugfile directory.  */
1484
  /* Then try in the global debugfile directory.  */
1438
  strcpy (debugfile, debug_file_directory);
1485
  strcpy (debugfile, debug_file_directory);
1439
  dirlen = strlen (debug_file_directory) - 1;
1486
  dirlen = strlen (debug_file_directory) - 1;
1440
  if (dirlen > 0
1487
  if (include_dirs)
1441
      && debug_file_directory[dirlen] != '/'
1488
    {
1442
      && canon_dir[0] != '/')
1489
      if (dirlen > 0
1443
    strcat (debugfile, "/");
1490
	  && debug_file_directory[dirlen] != '/'
1444
  strcat (debugfile, canon_dir);
1491
	  && canon_dir[0] != '/')
1492
	strcat (debugfile, "/");
1493
      strcat (debugfile, canon_dir);
1494
    }
1495
  else
1496
    {
1497
      if (dirlen > 0 && debug_file_directory[dirlen] != '/')
1498
	strcat (debugfile, "/");
1499
    }
1445
  strcat (debugfile, base);
1500
  strcat (debugfile, base);
1446
1501
1447
  if (check_func (debugfile, crc32))
1502
  if (check_func (debugfile, crc32))
Lines 1475-1483 DESCRIPTION Link Here
1475
	locations, including the directory tree rooted at @var{dir}, and if
1530
	locations, including the directory tree rooted at @var{dir}, and if
1476
	found returns the full filename.
1531
	found returns the full filename.
1477
1532
1478
	If @var{dir} is NULL, it will search a default path configured into
1533
	If @var{dir} is NULL, the search will take place starting at
1479
	libbfd at build time.  [XXX this feature is not currently
1534
	the current directory.
1480
	implemented].
1481
1535
1482
RETURNS
1536
RETURNS
1483
	<<NULL>> on any errors or failure to locate the .debug file,
1537
	<<NULL>> on any errors or failure to locate the .debug file,
Lines 1488-1494 RETURNS Link Here
1488
char *
1542
char *
1489
bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
1543
bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
1490
{
1544
{
1491
  return find_separate_debug_file (abfd, dir,
1545
  return find_separate_debug_file (abfd, dir, TRUE,
1492
				   bfd_get_debug_link_info,
1546
				   bfd_get_debug_link_info,
1493
				   separate_debug_file_exists);
1547
				   separate_debug_file_exists);
1494
}
1548
}
Lines 1522-1535 DESCRIPTION Link Here
1522
1576
1523
	Takes a BFD and searches it for a .gnu_debugaltlink section.  If this
1577
	Takes a BFD and searches it for a .gnu_debugaltlink section.  If this
1524
	section is found, it examines the section for the name of a file
1578
	section is found, it examines the section for the name of a file
1525
	containing auxiliary debugging information.  It	then searches the
1579
	containing auxiliary debugging information.  It then searches the
1526
	filesystem for this file in a set of standard locations, including
1580
	filesystem for this file in a set of standard locations, including
1527
	the directory tree rooted at @var{dir}, and if found returns the
1581
	the directory tree rooted at @var{dir}, and if found returns the
1528
	full filename.
1582
	full filename.
1529
1583
1530
	If @var{dir} is NULL, it will search a default path configured into
1584
	If @var{dir} is NULL, the search will take place starting at
1531
	libbfd at build time.  [FIXME: This feature is not currently
1585
	the current directory.
1532
	implemented].
1533
1586
1534
RETURNS
1587
RETURNS
1535
	<<NULL>> on any errors or failure to locate the debug file,
1588
	<<NULL>> on any errors or failure to locate the debug file,
Lines 1540-1546 RETURNS Link Here
1540
char *
1593
char *
1541
bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir)
1594
bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir)
1542
{
1595
{
1543
  return find_separate_debug_file (abfd, dir,
1596
  return find_separate_debug_file (abfd, dir, TRUE,
1544
				   get_alt_debug_link_info_shim,
1597
				   get_alt_debug_link_info_shim,
1545
				   separate_alt_debug_file_exists);
1598
				   separate_alt_debug_file_exists);
1546
}
1599
}
Lines 1695-1697 bfd_fill_in_gnu_debuglink_section (bfd *abfd, Link Here
1695
1748
1696
  return TRUE;
1749
  return TRUE;
1697
}
1750
}
1751
1752
/*
1753
INTERNAL_FUNCTION
1754
	get_build_id
1755
1756
SYNOPSIS
1757
	struct bfd_build_id * get_build_id
1758
	  (bfd *abfd);
1759
1760
DESCRIPTION
1761
	Finds the build-id associated with @var{abfd}.  If the build-id is
1762
	extracted from the note section then a build-id structure is built
1763
	for it, using memory allocated to @var{abfd}, and this is then
1764
	attached to the @var{abfd}.
1765
1766
	Returns a pointer to the build-id structure if a build-id could be
1767
	found.  If no build-id is found NULL is returned and error code is
1768
	set.
1769
*/
1770
1771
static struct bfd_build_id *
1772
get_build_id (bfd *abfd)
1773
{
1774
  struct bfd_build_id *build_id;
1775
  Elf_Internal_Note inote;
1776
  Elf_External_Note *enote;
1777
  bfd_byte *contents;
1778
  asection *sect;
1779
1780
  BFD_ASSERT (abfd);
1781
1782
  if (abfd->build_id && abfd->build_id->size > 0)
1783
    /* Save some time by using the already computed build-id.  */
1784
    return (struct bfd_build_id *) abfd->build_id;
1785
1786
  sect = bfd_get_section_by_name (abfd, ".note.gnu.build-id");
1787
  if (sect == NULL)
1788
    {
1789
      bfd_set_error (bfd_error_no_debug_section);
1790
      return NULL;
1791
    }
1792
1793
  /* FIXME: Should we support smaller build-id notes ?  */
1794
  if (bfd_get_section_size (sect) < 0x24)
1795
    {
1796
      bfd_set_error (bfd_error_invalid_operation);
1797
      return NULL;
1798
    }
1799
1800
  if (!bfd_malloc_and_get_section (abfd, sect, & contents))
1801
    {
1802
      if (contents != NULL)
1803
	free (contents);
1804
      return NULL;
1805
    }
1806
1807
  enote = (Elf_External_Note *) contents;
1808
  inote.type = H_GET_32 (abfd, enote->type);
1809
  inote.namesz = H_GET_32 (abfd, enote->namesz);
1810
  inote.namedata = enote->name;
1811
  inote.descsz = H_GET_32 (abfd, enote->descsz);
1812
  inote.descdata = inote.namedata + BFD_ALIGN (inote.namesz, 4);
1813
  /* FIXME: Should we check for extra notes in this section ?  */
1814
	  
1815
  if (inote.descsz == 0
1816
      || inote.type != NT_GNU_BUILD_ID
1817
      || inote.namesz != 4 /* sizeof "GNU"  */
1818
      || strcmp (inote.namedata, "GNU") != 0)
1819
    {
1820
      free (contents);
1821
      bfd_set_error (bfd_error_invalid_operation);
1822
      return NULL;
1823
    }
1824
1825
  build_id = bfd_alloc (abfd, sizeof (struct bfd_build_id) + inote.descsz);
1826
  if (build_id == NULL)
1827
    {
1828
      free (contents);
1829
      return NULL;
1830
    }
1831
1832
  build_id->size = inote.descsz;
1833
  memcpy (build_id->data, inote.descdata, inote.descsz);
1834
  abfd->build_id = build_id;
1835
  free (contents);
1836
1837
  return build_id;
1838
}
1839
1840
/*
1841
INTERNAL_FUNCTION
1842
	get_build_id_name
1843
1844
SYNOPSIS
1845
	char * get_build_id_name
1846
	  (bfd *abfd, unsigned long *build_id_out)
1847
1848
DESCRIPTION
1849
	Searches @var{abfd} for a build-id, and then constructs a pathname
1850
	from it.  The path is computed as .build-id/NN/NN+NN.debug where
1851
	NNNN+NN is the build-id value as a hexadecimal string.
1852
1853
	Returns the constructed filename or NULL upon error.
1854
	It is the caller's responsibility to free the memory used to hold the
1855
	filename.
1856
	If a filename is returned then the @var{build_id_out} parameter is
1857
	set to a pointer to the build_id structure.
1858
*/
1859
1860
static char *
1861
get_build_id_name (bfd *abfd, unsigned long *build_id_out)
1862
{
1863
  struct bfd_build_id *build_id;
1864
  char *name;
1865
  char *n;
1866
  bfd_size_type s;
1867
  bfd_byte *d;
1868
1869
  if (abfd == NULL || abfd->filename == NULL || build_id_out == NULL)
1870
    {
1871
      bfd_set_error (bfd_error_invalid_operation);
1872
      return NULL;
1873
    }
1874
1875
  build_id = get_build_id (abfd);
1876
  if (build_id == NULL)
1877
    return NULL;
1878
1879
  /* Compute the debug pathname corresponding to the build-id.  */
1880
  name = bfd_malloc (strlen (".build-id/") + build_id->size * 2 + 2 + strlen (".debug"));
1881
  if (name == NULL)
1882
    {
1883
      bfd_set_error (bfd_error_no_memory);
1884
      return NULL;
1885
    }
1886
  n = name;
1887
  d = build_id->data;
1888
  s = build_id->size;
1889
1890
  n += sprintf (n, ".build-id/");
1891
  n += sprintf (n, "%02x", (unsigned) *d++); s--;
1892
  n += sprintf (n, "/");
1893
  while (s--)
1894
    n += sprintf (n, "%02x", (unsigned) *d++);
1895
  n += sprintf (n, ".debug");
1896
1897
  * build_id_out = (unsigned long) build_id;
1898
  return name;
1899
}
1900
1901
/*
1902
INTERNAL_FUNCTION
1903
	check_build_id_file
1904
1905
SYNOPSIS
1906
	bfd_boolean check_build_id_file
1907
	  (char *name, unsigned long buildid);
1908
1909
DESCRIPTION
1910
	Checks to see if @var{name} is a readable file and if its build-id
1911
	matches @var{buildid}.
1912
1913
	Returns TRUE if the file exists, is readable, and contains a build-id
1914
	which matches @var{build-id}.
1915
*/
1916
1917
static bfd_boolean
1918
check_build_id_file (const char *name,
1919
		     const unsigned long buildid)
1920
{
1921
  struct bfd_build_id *orig_build_id;
1922
  struct bfd_build_id *build_id;
1923
  bfd * file;
1924
  bfd_boolean result;
1925
1926
  BFD_ASSERT (name);
1927
  BFD_ASSERT (buildid);
1928
1929
  file = bfd_openr (name, NULL);
1930
  if (file == NULL)
1931
    return FALSE;
1932
1933
  /* If the file is an archive, process all of its elements.  */
1934
  if (! bfd_check_format (file, bfd_object))
1935
    {
1936
      bfd_close (file);
1937
      return FALSE;
1938
    }
1939
  
1940
  build_id = get_build_id (file);
1941
  if (build_id == NULL)
1942
    {
1943
      bfd_close (file);
1944
      return FALSE;
1945
    }
1946
1947
  orig_build_id = (struct bfd_build_id *) buildid;
1948
1949
  result = build_id->size == orig_build_id->size
1950
    && memcmp (build_id->data, orig_build_id->data, build_id->size) == 0;
1951
1952
  (void) bfd_close (file);
1953
1954
  return result;
1955
}
1956
1957
/*
1958
FUNCTION
1959
	bfd_follow_build_id_debuglink
1960
1961
SYNOPSIS
1962
	char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir);
1963
1964
DESCRIPTION
1965
1966
	Takes @var{abfd} and searches it for a .note.gnu.build-id section.
1967
	If this section is found, it extracts the value of the NT_GNU_BUILD_ID
1968
	note, which should be a hexadecimal value @var{NNNN+NN} (for
1969
	32+ hex digits).  It then searches the filesystem for a file named
1970
	@var{.build-id/NN/NN+NN.debug} in a set of standard locations,
1971
	including the directory tree rooted at @var{dir}.  The filename
1972
	of the first matching file to be found is returned.  A matching
1973
	file should contain a .note.gnu.build-id section with the same
1974
	@var{NNNN+NN} note as @var{abfd}, although this check is currently
1975
	not implemented.
1976
1977
	If @var{dir} is NULL, the search will take place starting at
1978
	the current directory.
1979
1980
RETURNS
1981
	<<NULL>> on any errors or failure to locate the debug file,
1982
	otherwise a pointer to a heap-allocated string containing the
1983
	filename.  The caller is responsible for freeing this string.
1984
*/
1985
1986
char *
1987
bfd_follow_build_id_debuglink (bfd *abfd, const char *dir)
1988
{
1989
  return find_separate_debug_file (abfd, dir, FALSE,
1990
				   get_build_id_name,
1991
				   check_build_id_file);
1992
}
(-)a/binutils/testsuite/binutils-all/objdump.exp (+80 lines)
Lines 273-278 if { ![is_elf_format] } then { Link Here
273
    }
273
    }
274
}
274
}
275
275
276
proc test_build_id_debuglink {} {
277
    global srcdir
278
    global subdir
279
    global env
280
    global CC_FOR_TARGET
281
    global STRIP
282
    global OBJCOPY
283
    global OBJDUMP
284
    global CFLAGS_FOR_TARGET
285
    
286
    set test "build-id-debuglink"
287
    if {![info exists CC_FOR_TARGET]} {
288
	set CC_FOR_TARGET $env(CC)
289
    }
290
    if { $CC_FOR_TARGET == "" } {
291
	unsupported $test
292
	return
293
    }
294
295
    # Use a fixed build-id.
296
    set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01"
297
298
    if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog exectuable debug] != "" } {
299
	fail "$test (build)"
300
	return
301
    }
302
303
    # FIXME: Do we need to restore CFLAGS_FOR_TARGET to its old value ?
304
305
    if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog -o tmpdir/testprog.strip"] != "" } {
306
	fail "$test (strip debug info)"
307
	return
308
    }
309
310
    if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog tmpdir/testprog.debug"] != "" } {
311
	fail "$test (create separate debug info file)"
312
	return
313
    }
314
315
    set got [remote_exec host "mkdir -p .build-id/12" ]
316
    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
317
	fail "$test (make debug directory)"
318
	return
319
    }
320
321
    set got [remote_exec host "cp tmpdir/testprog.debug .build-id/12/345678abcdef01.debug"]
322
    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
323
	fail "$test (copy debug info into debug directory)"
324
	return
325
    }
326
    
327
    set got [remote_exec host "$OBJDUMP -Sl tmpdir/testprog.strip" "" "/dev/null" "tmpdir/testprog.strip.dump"]
328
    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
329
	fail "$test (post strip dump)"
330
	return
331
    }
332
333
    set src2 tmpdir/testprog.strip.dump
334
    verbose " grep -e testprog.c ${src2}"
335
    set status [remote_exec build grep "-e testprog.c ${src2}"]
336
    set exec_output [lindex $status 1]
337
    set exec_output [prune_warnings $exec_output]
338
    if [string match "" $exec_output] then {
339
	send_log "$exec_output\n"
340
	verbose "$exec_output" 1
341
	fail "$test (grepping for source file name in disassembly output)"
342
    } else {
343
	pass "$test"
344
	# Cleanup...
345
	set got [remote_exec host "rm .build-id/12/345678abcdef01.debug"]
346
	set got [remote_exec host "rmdir -p .build-id/12" ]
347
	set got [remote_exec host "rm tmpdir/testprog.strip.dump"]
348
	set got [remote_exec host "rm tmpdir/testprog.debug"]
349
	set got [remote_exec host "rm tmpdir/testprog.strip"]
350
    }
351
}
352
353
if {[isnative] && [is_elf_format]} then {
354
    test_build_id_debuglink
355
}
276
356
277
# Options which are not tested: -a -d -D -R -T -x -l --stabs
357
# Options which are not tested: -a -d -D -R -T -x -l --stabs
278
# I don't see any generic way to test any of these other than -a.
358
# I don't see any generic way to test any of these other than -a.

Return to bug 20876