[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-31 Thread danglin at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

John David Anglin  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||danglin at gcc dot gnu.org
 Resolution|--- |FIXED

--- Comment #12 from John David Anglin  ---
Fixed on trunk by commit 6d4b286.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread sch...@linux-m68k.org
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #5 from Andreas Schwab  ---
I think ld should error out if the output isn't a regular file.  There are
probably other cases where the linker needs to reread what it has written out.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread dave.anglin at bell dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #9 from dave.anglin at bell dot net ---
On 2016-01-30, at 1:14 PM, John David Anglin wrote:

> It seems to me we either have to match x86 behaviour, or the linker should 
> not allow writing
> to a non-regular file.

Something like to the following can check if the output file is a regular file.
 Various stat errors
could also be reported.

I'm not sure how portable this is.

Dave
--
John David Anglin   dave.ang...@bell.net

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread dave.anglin at bell dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #8 from dave.anglin at bell dot net ---
On 2016-01-30, at 8:51 AM, sch...@linux-m68k.org wrote:

> https://sourceware.org/bugzilla/show_bug.cgi?id=19526
> 
> --- Comment #7 from Andreas Schwab  ---
> The linker should not allow writing the output to a non-regular file in the
> first place.  Changing the behaviour depending on the type of output file 
> would
> be wrong.


Currently in bfd/opncls.c, there is the following code

  if (abfd->direction == write_direction
  && (abfd->flags & (EXEC_P | DYNAMIC)) != 0)
{
  struct stat buf;

  if (stat (abfd->filename, ) == 0
  /* Do not attempt to change non-regular files.  This is
 here especially for configure scripts and kernel builds
 which run tests with "ld [...] -o /dev/null".  */
  && S_ISREG(buf.st_mode))
{
  unsigned int mask = umask (0);

  umask (mask);
  chmod (abfd->filename,
 (0777
  & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask;
}
}

to support "ld [...] -o /dev/null".

It seems to me we either have to match x86 behaviour, or the linker should not
allow writing
to a non-regular file.

Dave
--
John David Anglin   dave.ang...@bell.net

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread sch...@linux-m68k.org
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #7 from Andreas Schwab  ---
The linker should not allow writing the output to a non-regular file in the
first place.  Changing the behaviour depending on the type of output file would
be wrong.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread deller at gmx dot de
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #6 from Helge Deller  ---
Andreas wrote:
> I think ld should error out if the output isn't a regular file.

It currently does error out with a "final link failed: File truncated" error in
that case. But that's actually the problem. It shouldn't error out as I
described in the bug report.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread amodra at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #11 from Alan Modra  ---
Ah, never mind about S_ISLNK.  You're using stat, not lstat.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-30 Thread amodra at gmail dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

Alan Modra  changed:

   What|Removed |Added

 CC||amodra at gmail dot com

--- Comment #10 from Alan Modra  ---
Dave, I like your first patch, but you should probably allow S_ISLNK too.  The
second will only cause grief for distros.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-29 Thread dave.anglin at bell dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #2 from dave.anglin at bell dot net ---
On 2016-01-29 4:17 PM, deller at gmx dot de wrote:
> https://sourceware.org/bugzilla/show_bug.cgi?id=19526
>
> --- Comment #1 from Helge Deller  ---
> The debian "libbsd" package fails because of the same issue:
>
> gcc -isystem ../include/bsd -I.. -include ../config.h
> -DLIBBSD_DISABLE_DEPRECATED -D__REENTRANT -DLIBBSD_OVERLAY
> headers-overlay-gen.c -o /dev/null
> /usr/bin/ld: final link failed: File truncated
> collect2: error: ld returned 1 exit status
> FAIL headers-overlay.sh (exit status: 1)
>
> Full log:
> https://buildd.debian.org/status/fetch.php?pkg=libbsd=hppa=0.8.2-1=1453935236
>
I have built a debug version of binutils.  I'll see if I can find 
problem this weekend.

Dave

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-29 Thread dave.anglin at bell dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #3 from dave.anglin at bell dot net ---
It's not necessary to use a pipe to duplicate.  I created a file xxx.c with
'int main(){}' and
compiled with -save-temps and -Wl,-debug to get the actual link command.  Here
is backtrace
for bfd_error_file_truncated:

Breakpoint 4, bfd_set_error (error_tag=724328) at ../../src/bfd/bfd.c:511
511   va_start (ap, error_tag);
(gdb) step
503 {
(gdb) 
504   bfd_error = error_tag;
(gdb) 
505   if (error_tag == bfd_error_on_input)
(gdb) p bfd_error
$3 = bfd_error_file_truncated
(gdb) bt
#0  bfd_set_error (error_tag=bfd_error_file_truncated)
at ../../src/bfd/bfd.c:505
#1  0xfd1ade30 in cache_bread_1 (abfd=0xaecb0, buf=0x257978, nbytes=256)
at ../../src/bfd/cache.c:347
#2  0xfd1adf60 in cache_bread (abfd=0xaecb0, buf=0x257978, nbytes=256)
at ../../src/bfd/cache.c:368
#3  0xfd1ac17c in bfd_bread (ptr=0x257978, size=256, abfd=0xaecb0)
at ../../src/bfd/bfdio.c:196
#4  0xfd1b6000 in _bfd_generic_get_section_contents (abfd=0xaecb0, 
section=0xb0850, location=0x257978, offset=0, count=256)
at ../../src/bfd/libbfd.c:812
#5  0xfd1ca458 in bfd_get_section_contents (abfd=0xaecb0, section=0xb0850, 
location=0x257978, offset=0, count=256) at ../../src/bfd/section.c:1619
#6  0xfd1af8c4 in bfd_get_full_section_contents (abfd=0xaecb0, sec=0xb0850, 
ptr=0xfd7034d0) at ../../src/bfd/compress.c:253
#7  0xfd1ca4d8 in bfd_malloc_and_get_section (abfd=0xaecb0, sec=0xb0850, 
buf=0xfd7034d0) at ../../src/bfd/section.c:1640
#8  0xfd1ddb4c in elf_hppa_sort_unwind (abfd=0xaecb0)
at ../../src/bfd/elf-hppa.h:1196
#9  0xfd1e6030 in elf32_hppa_final_link (abfd=0xaecb0, 
info=0x9f5b0 ) at ../../src/bfd/elf32-hppa.c:3257
#10 0x00049010 in ldwrite () at ../../src/ld/ldwrite.c:581
#11 0x00043bd8 in main (argc=38, argv=0xfd70302c) at ../../src/ld/ldmain.c:430
(gdb) frame 8
#8  0xfd1ddb4c in elf_hppa_sort_unwind (abfd=0xaecb0)
at ../../src/bfd/elf-hppa.h:1196
1196  if (!bfd_malloc_and_get_section (abfd, s, ))
(gdb) p *abfd
$4 = {filename = 0xb0d58 "/dev/null", 
  xvec = 0xfd2d07b8 , iostream = 0xb0d68, 
  iovec = 0xfd2c90a0 , lru_prev = 0xc5738, lru_next = 0x118568, 
  where = 2228, mtime = 0, id = 0, format = bfd_object, 
  direction = write_direction, flags = 386, cacheable = 1, 
  target_defaulted = 0, opened_once = 1, mtime_set = 0, no_export = 0, 
  output_has_begun = 1, has_armap = 0, is_thin_archive = 0, 
  selective_search = 0, is_linker_output = 1, is_linker_input = 0, 
  plugin_format = bfd_plugin_uknown, lto_output = 0, plugin_dummy_bfd = 0x0, 
  origin = 0, proxy_origin = 0, section_htab = {table = 0x232490, 
newfunc = @0xfd42031e: 0xfd1c8b08 , 
memory = 0xafd60, size = 61, count = 31, entsize = 184, frozen = 0}, 
  sections = 0xafdc0, section_last = 0x232878, section_count = 27, 
  archive_pass = 0, start_address = 66496, outsymbols = 0x0, symcount = 93, 
  dynsymcount = 0, arch_info = 0xfd2d1140 , arelt_data = 0x0, 
  my_archive = 0x0, archive_next = 0x0, archive_head = 0x0, 
  nested_archives = 0x0, link = {next = 0xb0ed0, hash = 0xb0ed0}, tdata = {
aout_data = 0xaed80, aout_ar_data = 0xaed80, oasys_obj_data = 0xaed80, 
oasys_ar_data = 0xaed80, coff_obj_data = 0xaed80, pe_obj_data = 0xaed80, 
xcoff_obj_data = 0xaed80, ecoff_obj_data = 0xaed80, ieee_data = 0xaed80, 
ieee_ar_data = 0xaed80, srec_data = 0xaed80, verilog_data = 0xaed80, 
ihex_data = 0xaed80, tekhex_data = 0xaed80, elf_obj_data = 0xaed80, 
nlm_obj_data = 0xaed80, bout_data = 0xaed80, mmo_data = 0xaed80, 
sun_core_data = 0xaed80, sco5_core_data = 0xaed80, 
trad_core_data = 0xaed80, som_data = 0xaed80, hpux_core_data = 0xaed80, 
hppabsd_core_data = 0xaed80, sgi_core_data = 0xaed80, 
lynx_core_data = 0xaed80, osf_core_data = 0xaed80, 
cisco_core_data = 0xaed80, versados_data = 0xaed80, 
netbsd_core_data = 0xaed80, mach_o_data = 0xaed80, 
mach_o_fat_data = 0xaed80, plugin_data = 0xaed80, pef_data = 0xaed80, 
pef_xlib_data = 0xaed80, sym_data = 0xaed80, any = 0xaed80}, 
  usrdata = 0x0, memory = 0xaed68, build_id = 0x0}

Maybe skipping sort when filename is "/dev/null" will fix.

Is there a better test?

Dave
--
John David Anglin   dave.ang...@bell.net

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-29 Thread dave.anglin at bell dot net
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #4 from dave.anglin at bell dot net ---
On 2016-01-29, at 9:05 PM, John David Anglin wrote:

> Maybe skipping sort when filename is "/dev/null" will fix.

Untested fix.

--
John David Anglin   dave.ang...@bell.net

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/19526] Using "gcc -o /dev/null" gives "ld: final link failed: File truncated" error

2016-01-29 Thread deller at gmx dot de
https://sourceware.org/bugzilla/show_bug.cgi?id=19526

--- Comment #1 from Helge Deller  ---
The debian "libbsd" package fails because of the same issue:

gcc -isystem ../include/bsd -I.. -include ../config.h
-DLIBBSD_DISABLE_DEPRECATED -D__REENTRANT -DLIBBSD_OVERLAY
headers-overlay-gen.c -o /dev/null
/usr/bin/ld: final link failed: File truncated
collect2: error: ld returned 1 exit status
FAIL headers-overlay.sh (exit status: 1)

Full log:
https://buildd.debian.org/status/fetch.php?pkg=libbsd=hppa=0.8.2-1=1453935236

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils