Skip to content

Commit 6d4b286

Browse files
author
John David Anglin
committed
Fix /usr/bin/ld: final link failed: File truncated error on hppa.
1 parent d9e3b59 commit 6d4b286

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

bfd/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2016-01-31 John David Anglin <[email protected]>
2+
3+
PR ld/19526
4+
* elf32-hppa.c (elf32_hppa_final_link): Don't sort non-regular output
5+
files.
6+
* elf64-hppa.c (elf32_hppa_final_link): Likewise. Remove retval.
7+
18
2016-01-30 H.J. Lu <[email protected]>
29

310
PR ld/19539

bfd/elf32-hppa.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,8 @@ tpoff (struct bfd_link_info *info, bfd_vma address)
32453245
static bfd_boolean
32463246
elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
32473247
{
3248+
struct stat buf;
3249+
32483250
/* Invoke the regular ELF linker to do all the work. */
32493251
if (!bfd_elf_final_link (abfd, info))
32503252
return FALSE;
@@ -3254,6 +3256,13 @@ elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
32543256
if (bfd_link_relocatable (info))
32553257
return TRUE;
32563258

3259+
/* Do not attempt to sort non-regular files. This is here
3260+
especially for configure scripts and kernel builds which run
3261+
tests with "ld [...] -o /dev/null". */
3262+
if (stat (abfd->filename, &buf) != 0
3263+
|| !S_ISREG(buf.st_mode))
3264+
return TRUE;
3265+
32573266
return elf_hppa_sort_unwind (abfd);
32583267
}
32593268

bfd/elf64-hppa.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,7 @@ elf_hppa_record_segment_addrs (bfd *abfd,
29452945
static bfd_boolean
29462946
elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
29472947
{
2948-
bfd_boolean retval;
2948+
struct stat buf;
29492949
struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info);
29502950

29512951
if (hppa_info == NULL)
@@ -3029,18 +3029,26 @@ elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
30293029
info);
30303030

30313031
/* Invoke the regular ELF backend linker to do all the work. */
3032-
retval = bfd_elf_final_link (abfd, info);
3032+
if (!bfd_elf_final_link (abfd, info))
3033+
return FALSE;
30333034

30343035
elf_link_hash_traverse (elf_hash_table (info),
30353036
elf_hppa_remark_useless_dynamic_symbols,
30363037
info);
30373038

30383039
/* If we're producing a final executable, sort the contents of the
30393040
unwind section. */
3040-
if (retval && !bfd_link_relocatable (info))
3041-
retval = elf_hppa_sort_unwind (abfd);
3041+
if (bfd_link_relocatable (info))
3042+
return TRUE;
3043+
3044+
/* Do not attempt to sort non-regular files. This is here
3045+
especially for configure scripts and kernel builds which run
3046+
tests with "ld [...] -o /dev/null". */
3047+
if (stat (abfd->filename, &buf) != 0
3048+
|| !S_ISREG(buf.st_mode))
3049+
return TRUE;
30423050

3043-
return retval;
3051+
return elf_hppa_sort_unwind (abfd);
30443052
}
30453053

30463054
/* Relocate the given INSN. VALUE should be the actual value we want

0 commit comments

Comments
 (0)