aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2011-06-29 21:57:51 +0000
committerIan Lance Taylor <ian@airs.com>2011-06-29 21:57:51 +0000
commit37e41b0352ff18c675a8566789087ba560825d91 (patch)
treea11a5fb6fb509b3138202c1ba82cc3c060a1a1ad /gold
parent6c21fce1ccdbd1f73152e6dbd90cfe04738c54fe (diff)
downloadgdb-37e41b0352ff18c675a8566789087ba560825d91.zip
gdb-37e41b0352ff18c675a8566789087ba560825d91.tar.gz
gdb-37e41b0352ff18c675a8566789087ba560825d91.tar.bz2
* script.cc (Token::integer_value): Accept trailing M/m/K/k
modifier. (Lex::gather_token): Accept trailing M/m/K/k for integers.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog1
-rw-r--r--gold/script.cc50
2 files changed, 40 insertions, 11 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index e929226..ae21427 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,5 +1,6 @@
2011-06-29 Ian Lance Taylor <iant@google.com>
+ PR gold/12652
* script.cc (Token::integer_value): Accept trailing M/m/K/k
modifier.
(Lex::gather_token): Accept trailing M/m/K/k for integers.
diff --git a/gold/script.cc b/gold/script.cc
index 33a8981..7df0c9e 100644
--- a/gold/script.cc
+++ b/gold/script.cc
@@ -146,13 +146,7 @@ class Token
}
uint64_t
- integer_value() const
- {
- gold_assert(this->classification_ == TOKEN_INTEGER);
- // Null terminate.
- std::string s(this->value_, this->value_length_);
- return strtoull(s.c_str(), NULL, 0);
- }
+ integer_value() const;
private:
// The token classification.
@@ -171,6 +165,35 @@ class Token
int charpos_;
};
+// Return the value of a TOKEN_INTEGER.
+
+uint64_t
+Token::integer_value() const
+{
+ gold_assert(this->classification_ == TOKEN_INTEGER);
+
+ size_t len = this->value_length_;
+
+ uint64_t multiplier = 1;
+ char last = this->value_[len - 1];
+ if (last == 'm' || last == 'M')
+ {
+ multiplier = 1024 * 1024;
+ --len;
+ }
+ else if (last == 'k' || last == 'K')
+ {
+ multiplier = 1024;
+ --len;
+ }
+
+ char *end;
+ uint64_t ret = strtoull(this->value_, &end, 0);
+ gold_assert(static_cast<size_t>(end - this->value_) == len);
+
+ return ret * multiplier;
+}
+
// This class handles lexing a file into a sequence of tokens.
class Lex
@@ -474,9 +497,7 @@ Lex::can_continue_name(const char* c)
// For a number we accept 0x followed by hex digits, or any sequence
// of digits. The old linker accepts leading '$' for hex, and
// trailing HXBOD. Those are for MRI compatibility and we don't
-// accept them. The old linker also accepts trailing MK for mega or
-// kilo. FIXME: Those are mentioned in the documentation, and we
-// should accept them.
+// accept them.
// Return whether C1 C2 C3 can start a hex number.
@@ -703,8 +724,15 @@ Lex::gather_token(Token::Classification classification,
const char** pp)
{
const char* new_match = NULL;
- while ((new_match = (this->*can_continue_fn)(match)))
+ while ((new_match = (this->*can_continue_fn)(match)) != NULL)
match = new_match;
+
+ // A special case: integers may be followed by a single M or K,
+ // case-insensitive.
+ if (classification == Token::TOKEN_INTEGER
+ && (*match == 'm' || *match == 'M' || *match == 'k' || *match == 'K'))
+ ++match;
+
*pp = match;
return this->make_token(classification, start, match - start, start);
}