From f82861394575eb95586884ec0f8907a4126d5c6a Mon Sep 17 00:00:00 2001 From: Hemant Kulkarni Date: Mon, 5 Nov 2012 19:13:54 +0000 Subject: [PATCH] Add absolute symbol scope recognition in lld/Core llvm-svn: 167394 --- lld/lib/Core/Resolver.cpp | 4 +++- lld/lib/ReaderWriter/YAML/ReaderYAML.cpp | 12 +++++++----- lld/test/absolute-local.objtxt | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 lld/test/absolute-local.objtxt diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 018cb0a..8b426fa 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -151,7 +151,9 @@ void Resolver::doAbsoluteAtom(const AbsoluteAtom& atom) { _atoms.push_back(&atom); // tell symbol table - _symbolTable.add(atom); + if (atom.scope() != Atom::scopeTranslationUnit) { + _symbolTable.add(atom); + } } diff --git a/lld/lib/ReaderWriter/YAML/ReaderYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderYAML.cpp index bf8e70c..bb0a272 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderYAML.cpp @@ -419,10 +419,11 @@ private: /// class YAMLAbsoluteAtom : public AbsoluteAtom { public: - YAMLAbsoluteAtom(YAMLFile &f, int32_t, StringRef name, uint64_t v) + YAMLAbsoluteAtom(YAMLFile &f, int32_t, StringRef name, uint64_t v, Atom::Scope scope) : _file(f) , _name(name) - , _value(v) { + , _value(v) + , _scope(scope){ } virtual const class File &file() const { @@ -430,7 +431,7 @@ public: } virtual Scope scope() const { - return scopeGlobal; + return _scope; } virtual StringRef name() const { @@ -445,6 +446,7 @@ private: YAMLFile &_file; StringRef _name; uint64_t _value; + Atom::Scope _scope; }; @@ -779,7 +781,8 @@ void YAMLState::makeAbsoluteAtom(Node *node) { + "' has attributes only allowed on shared library atoms"); _error = make_error_code(yaml_reader_error::illegal_value); } - AbsoluteAtom *a = new YAMLAbsoluteAtom(*_file, _ordinal, _name, _value); + AbsoluteAtom *a = new YAMLAbsoluteAtom(*_file, _ordinal, _name, _value, + _scope); _file->addAbsoluteAtom(a); } @@ -939,7 +942,6 @@ void YAMLState::parseAtomScope(ScalarNode *node) { _stream->printError(node, "Invalid value for 'scope:'"); _error = make_error_code(yaml_reader_error::illegal_value); } - _hasDefinedAtomAttributes = true; } void YAMLState::parseAtomDefinition(ScalarNode *node) { diff --git a/lld/test/absolute-local.objtxt b/lld/test/absolute-local.objtxt new file mode 100644 index 0000000..0db54e5 --- /dev/null +++ b/lld/test/absolute-local.objtxt @@ -0,0 +1,26 @@ +# RUN: lld-core %s | FileCheck %s + +# +# Test that absolute symbols with local scope do not cause name conflict +# +--- +atoms: + - name: putchar + definition: absolute + value: 0xFFFF0040 + scope: static + + - name: putchar + definition: absolute + value: 0xFFFF0040 + scope: static +... + +# CHECK: --- +# CHECK: - name: putchar +# CHECK: definition: absolute +# CHECK: value: 0xffff0040 +# CHECK: - name: putchar +# CHECK: definition: absolute +# CHECK: value: 0xffff0040 +# CHECK: ... -- 2.7.4