* [gold patch] Fix problem where --incremental-base with huge file reports "file too short"
@ 2011-10-11 23:34 Cary Coutant
2011-10-12 17:47 ` Cary Coutant
0 siblings, 1 reply; 4+ messages in thread
From: Cary Coutant @ 2011-10-11 23:34 UTC (permalink / raw)
To: Ian Lance Taylor, Binutils
When running the linker with --incremental-base pointing to a file
larger than 2GB, I found that I forgot to handle the case where read()
might return early. This patch adds a loop around the read().
Tested on x86_64. OK to commit?
-cary
2011-10-11 Cary Coutant <ccoutant@google.com>
* gold/output.cc (Output_file::open_base_file): Handle case where
::read returns less than requested size.
commit 70a0d37b350ac98d58a27a0df20a2c2137d74016
Author: Cary Coutant <ccoutant@google.com>
Date: Tue Oct 11 16:27:17 2011 -0700
Add loop around ::read when reading base file.
diff --git a/gold/output.cc b/gold/output.cc
index d6bdaba..2618f88 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -4893,17 +4893,27 @@ Output_file::open_base_file(const char*
base_name, bool writable)
if (use_base_file)
{
this->open(s.st_size);
- ssize_t len = ::read(o, this->base_, s.st_size);
- if (len < 0)
- {
- gold_info(_("%s: read failed: %s"), base_name, strerror(errno));
- return false;
- }
- if (len < s.st_size)
- {
- gold_info(_("%s: file too short"), base_name);
- return false;
- }
+ ssize_t base_size = s.st_size;
+ unsigned char* base = this->base_;
+ while (base_size > 0)
+ {
+ ssize_t len = ::read(o, base, base_size);
+ if (len < 0)
+ {
+ gold_info(_("%s: read failed: %s"), base_name, strerror(errno));
+ return false;
+ }
+ if (len == 0)
+ {
+ gold_info(_("%s: file too short: read only %lld of %lld bytes"),
+ base_name,
+ static_cast<long long>(s.st_size - base_size),
+ static_cast<long long>(s.st_size));
+ return false;
+ }
+ base += len;
+ base_size -= len;
+ }
::close(o);
return true;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gold patch] Fix problem where --incremental-base with huge file reports "file too short"
2011-10-11 23:34 [gold patch] Fix problem where --incremental-base with huge file reports "file too short" Cary Coutant
@ 2011-10-12 17:47 ` Cary Coutant
2011-10-13 2:41 ` Ian Lance Taylor
0 siblings, 1 reply; 4+ messages in thread
From: Cary Coutant @ 2011-10-12 17:47 UTC (permalink / raw)
To: Ian Lance Taylor, Binutils
Looking over this patch this morning, I realized that there's a
potential confusion between "this->base_", base, and base_size, so I
renamed the latter two variables. Here's the revised patch...
-cary
2011-10-11 Cary Coutant <ccoutant@google.com>
* gold/output.cc (Output_file::open_base_file): Handle case where
::read returns less than requested size.
commit 4dbbb5bf9166e62d8fdfbf8184f2ef94b7ce3afb
Author: Cary Coutant <ccoutant@google.com>
Date: Tue Oct 11 16:27:17 2011 -0700
Add loop around ::read when reading base file.
diff --git a/gold/output.cc b/gold/output.cc
index d6bdaba..7b272e8 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -4893,17 +4893,27 @@ Output_file::open_base_file(const char*
base_name, bool writable)
if (use_base_file)
{
this->open(s.st_size);
- ssize_t len = ::read(o, this->base_, s.st_size);
- if (len < 0)
- {
- gold_info(_("%s: read failed: %s"), base_name, strerror(errno));
- return false;
- }
- if (len < s.st_size)
- {
- gold_info(_("%s: file too short"), base_name);
- return false;
- }
+ ssize_t bytes_to_read = s.st_size;
+ unsigned char* p = this->base_;
+ while (bytes_to_read > 0)
+ {
+ ssize_t len = ::read(o, p, bytes_to_read);
+ if (len < 0)
+ {
+ gold_info(_("%s: read failed: %s"), base_name, strerror(errno));
+ return false;
+ }
+ if (len == 0)
+ {
+ gold_info(_("%s: file too short: read only %lld of %lld bytes"),
+ base_name,
+ static_cast<long long>(s.st_size - bytes_to_read),
+ static_cast<long long>(s.st_size));
+ return false;
+ }
+ p += len;
+ bytes_to_read -= len;
+ }
::close(o);
return true;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gold patch] Fix problem where --incremental-base with huge file reports "file too short"
2011-10-12 17:47 ` Cary Coutant
@ 2011-10-13 2:41 ` Ian Lance Taylor
2011-10-13 5:56 ` Cary Coutant
0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2011-10-13 2:41 UTC (permalink / raw)
To: Cary Coutant; +Cc: Binutils
Cary Coutant <ccoutant@google.com> writes:
> 2011-10-11 Cary Coutant <ccoutant@google.com>
>
> * gold/output.cc (Output_file::open_base_file): Handle case where
> ::read returns less than requested size.
This is OK.
Thanks.
Ian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [gold patch] Fix problem where --incremental-base with huge file reports "file too short"
2011-10-13 2:41 ` Ian Lance Taylor
@ 2011-10-13 5:56 ` Cary Coutant
0 siblings, 0 replies; 4+ messages in thread
From: Cary Coutant @ 2011-10-13 5:56 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: Binutils
>> 2011-10-11 Cary Coutant <ccoutant@google.com>
>>
>> * gold/output.cc (Output_file::open_base_file): Handle case where
>> ::read returns less than requested size.
>
> This is OK.
Thanks, committed.
-cary
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-13 5:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-11 23:34 [gold patch] Fix problem where --incremental-base with huge file reports "file too short" Cary Coutant
2011-10-12 17:47 ` Cary Coutant
2011-10-13 2:41 ` Ian Lance Taylor
2011-10-13 5:56 ` Cary Coutant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).