Add absolute symbol scope recognition in lld/Core
authorHemant Kulkarni <khemant@codeaurora.org>
Mon, 5 Nov 2012 19:13:54 +0000 (19:13 +0000)
committerHemant Kulkarni <khemant@codeaurora.org>
Mon, 5 Nov 2012 19:13:54 +0000 (19:13 +0000)
llvm-svn: 167394

lld/lib/Core/Resolver.cpp
lld/lib/ReaderWriter/YAML/ReaderYAML.cpp
lld/test/absolute-local.objtxt [new file with mode: 0644]

index 018cb0a..8b426fa 100644 (file)
@@ -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);
+  }
 }
 
 
index bf8e70c..bb0a272 100644 (file)
@@ -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 (file)
index 0000000..0db54e5
--- /dev/null
@@ -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:       ...