[llvm] r259318 - [dsymutil] Fix handling of common symbols.
Frederic Riss via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 30 20:29:34 PST 2016
Author: friss
Date: Sat Jan 30 22:29:34 2016
New Revision: 259318
URL: http://llvm.org/viewvc/llvm-project?rev=259318&view=rev
Log:
[dsymutil] Fix handling of common symbols.
llvm-dsymutil was misinterpreting the value of common symbols as their
address when it actually contains their size. This didn't impact
llvm-dsymutil's ability to link the debug information for common symbols
because these are always found by name and not by address. Things could
however go wrong when the size of a common object matched the object
file address of another symbol. Depending on the link order of the symbols
the common object might incorrectly evict this other object from the
address to symbol mapping, and then link the evicted symbol with a wrong
binary address.
Use the new ability to have symbols without an object file address to fix
this.
Added:
llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64 (with props)
llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64.o
llvm/trunk/test/tools/dsymutil/X86/common-sym.test
Modified:
llvm/trunk/test/tools/dsymutil/absolute_symbol.test
llvm/trunk/test/tools/dsymutil/basic-linking.test
llvm/trunk/test/tools/dsymutil/debug-map-parsing.test
llvm/trunk/test/tools/dsymutil/yaml-object-address-rewrite.test
llvm/trunk/tools/dsymutil/DebugMap.cpp
llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
Added: llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64?rev=259318&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64 (added) and llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64 Sat Jan 30 22:29:34 2016 differ
Propchange: llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64
------------------------------------------------------------------------------
svn:executable = *
Added: llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64.o?rev=259318&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/common.macho.x86_64.o Sat Jan 30 22:29:34 2016 differ
Added: llvm/trunk/test/tools/dsymutil/X86/common-sym.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/common-sym.test?rev=259318&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/common-sym.test (added)
+++ llvm/trunk/test/tools/dsymutil/X86/common-sym.test Sat Jan 30 22:29:34 2016
@@ -0,0 +1,24 @@
+RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/common.macho.x86_64 -f -o - | llvm-dwarfdump -debug-dump=info - | Filecheck %s
+
+The test was compiled from a single source:
+$ cat common.c
+char common[16];
+int main() { return 0;}
+void bar() {}
+$ clang -g -c common.c -o common.macho.x86_64.o
+$ clang common.macho.x86_64.o -o common.macho.x86_64
+
+CHECK: DW_TAG_variable
+CHECK: DW_AT_name {{.*}} "common"
+CHECK-NOT: {{NULL|DW_TAG}}
+CHECK: DW_AT_location {{.*}} (<0x09> 03 00 10 00 00 01 00 00 00 )
+
+CHECK: DW_TAG_subprogram
+CHECK-NEXT: DW_AT_low_pc{{.*}}(0x0000000100000f80)
+CHECK-NOT: {{NULL|DW_TAG}}
+CHECK: DW_AT_name {{.*}} "main"
+
+CHECK: DW_TAG_subprogram
+CHECK-NEXT: DW_AT_low_pc{{.*}}(0x0000000100000f90)
+CHECK-NOT: {{NULL|DW_TAG}}
+CHECK: DW_AT_name {{.*}} "bar"
Modified: llvm/trunk/test/tools/dsymutil/absolute_symbol.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/absolute_symbol.test?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/absolute_symbol.test (original)
+++ llvm/trunk/test/tools/dsymutil/absolute_symbol.test Sat Jan 30 22:29:34 2016
@@ -13,4 +13,5 @@ compiled for i386. This create an absolu
We must not consider this symbol for debug info linking as its address
might conflict with other real symbols in the same file.
-CHECK-NOT: objc_class_name_Foo
+CHECK: objc_class_name_Foo
+CHECK-SAME-NOT: objAddr
Modified: llvm/trunk/test/tools/dsymutil/basic-linking.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/basic-linking.test?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/basic-linking.test (original)
+++ llvm/trunk/test/tools/dsymutil/basic-linking.test Sat Jan 30 22:29:34 2016
@@ -44,7 +44,7 @@ CHECK-NEXT: TAG_compile_unit
CHECK-NOT: TAG
CHECK: AT_name {{.*}}basic3.c
CHECK-NOT: Found valid debug map entry
-CHECK: Found valid debug map entry: _val 0000000000000004 => 0000000100001004
+CHECK: Found valid debug map entry: _val ffffffffffffffff => 0000000100001004
CHECK-NEXT: DW_TAG_variable
CHECK-NEXT: DW_AT_name {{.*}}"val"
CHECK-NOT: Found valid debug map entry
@@ -137,7 +137,7 @@ CHECK-ARCHIVE-NEXT: TAG_compile_unit
CHECK-ARCHIVE-NOT: TAG
CHECK-ARCHIVE: AT_name {{.*}}basic3.c
CHECK-ARCHIVE-NOT: Found valid debug map entry
-CHECK-ARCHIVE: Found valid debug map entry: _val 0000000000000004 => 0000000100001008
+CHECK-ARCHIVE: Found valid debug map entry: _val ffffffffffffffff => 0000000100001008
CHECK-ARCHIVE-NEXT: DW_TAG_variable
CHECK-ARCHIVE-NEXT: DW_AT_name {{.*}}"val"
CHECK-ARCHIVE-NOT: Found valid debug map entry
Modified: llvm/trunk/test/tools/dsymutil/debug-map-parsing.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/debug-map-parsing.test?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/debug-map-parsing.test (original)
+++ llvm/trunk/test/tools/dsymutil/debug-map-parsing.test Sat Jan 30 22:29:34 2016
@@ -21,7 +21,7 @@ CHECK-DAG: sym: _private_int, objAddr:
CHECK: filename{{.*}}/Inputs/basic3.macho.x86_64.o
CHECK-DAG: sym: _bar, objAddr: 0x0000000000000020, binAddr: 0x0000000100000F40, size: 0x00000050
CHECK-DAG: sym: _inc, objAddr: 0x0000000000000070, binAddr: 0x0000000100000F90, size: 0x00000019
-CHECK-DAG: sym: _val, objAddr: 0x0000000000000004, binAddr: 0x0000000100001004, size: 0x00000000
+CHECK-DAG: sym: _val, binAddr: 0x0000000100001004, size: 0x00000000
CHECK: ...
@@ -65,7 +65,7 @@ CHECK-ARCHIVE-DAG: sym: _private_int, o
CHECK-ARCHIVE: /Inputs/./libbasic.a(basic3.macho.x86_64.o)
CHECK-ARCHIVE-DAG: sym: _bar, objAddr: 0x0000000000000020, binAddr: 0x0000000100000F40, size: 0x00000050
CHECK-ARCHIVE-DAG: sym: _inc, objAddr: 0x0000000000000070, binAddr: 0x0000000100000F90, size: 0x00000019
-CHECK-ARCHIVE-DAG: sym: _val, objAddr: 0x0000000000000004, binAddr: 0x0000000100001008, size: 0x00000000
+CHECK-ARCHIVE-DAG: sym: _val, binAddr: 0x0000000100001008, size: 0x00000000
CHECK-ARCHIVE: ...
Check that we warn about missing object files (this presumes that the files aren't
Modified: llvm/trunk/test/tools/dsymutil/yaml-object-address-rewrite.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/yaml-object-address-rewrite.test?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/yaml-object-address-rewrite.test (original)
+++ llvm/trunk/test/tools/dsymutil/yaml-object-address-rewrite.test Sat Jan 30 22:29:34 2016
@@ -23,7 +23,7 @@
# CHECK-NEXT: filename:{{.*}}/Inputs/./libbasic.a(basic3.macho.x86_64.o)'
# CHECK-NEXT: timestamp: 0
# CHECK-NEXT: symbols:
-# CHECK-DAG: sym: _val, objAddr: 0x0000000000000004, binAddr: 0x0000000100001008, size: 0x00000000
+# CHECK-DAG: sym: _val, binAddr: 0x0000000100001008, size: 0x00000000
# CHECK-DAG: sym: _bar, objAddr: 0x0000000000000020, binAddr: 0x0000000100000F40, size: 0x00000050
# CHECK-DAG: sym: _inc, objAddr: 0x0000000000000070, binAddr: 0x0000000100000F90, size: 0x00000019
# CHECK-NOT: { sym:
@@ -42,7 +42,7 @@ objects:
- { sym: _baz, objAddr: 0x0, binAddr: 0x0000000100001000, size: 0x00000000 }
- filename: /Inputs/./libbasic.a(basic3.macho.x86_64.o)
symbols:
- - { sym: _val, objAddr: 0x0, binAddr: 0x0000000100001008, size: 0x00000000 }
+ - { sym: _val, binAddr: 0x0000000100001008, size: 0x00000000 }
- { sym: _bar, objAddr: 0x0, binAddr: 0x0000000100000F40, size: 0x00000050 }
- { sym: _inc, objAddr: 0x0, binAddr: 0x0000000100000F90, size: 0x00000019 }
...
Modified: llvm/trunk/tools/dsymutil/DebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.cpp?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.cpp (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.cpp Sat Jan 30 22:29:34 2016
@@ -229,7 +229,8 @@ MappingTraits<dsymutil::DebugMapObject>:
for (const auto &Sym : ErrOrObjectFile->symbols()) {
uint64_t Address = Sym.getValue();
ErrorOr<StringRef> Name = Sym.getName();
- if (!Name)
+ if (!Name ||
+ (Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common)))
continue;
SymbolAddresses[*Name] = Address;
}
Modified: llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp?rev=259318&r1=259317&r2=259318&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachODebugMapParser.cpp Sat Jan 30 22:29:34 2016
@@ -389,8 +389,6 @@ void MachODebugMapParser::handleStabSymb
if (ObjectSymIt == CurrentObjectAddresses.end())
return Warning("could not find object file symbol for symbol " +
Twine(Name));
- if (!ObjectSymIt->getValue())
- return;
if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value,
Size))
return Warning(Twine("failed to insert symbol '") + Name +
@@ -407,12 +405,15 @@ void MachODebugMapParser::loadCurrentObj
ErrorOr<StringRef> Name = Sym.getName();
if (!Name)
continue;
- // Objective-C on i386 uses artificial absolute symbols to
- // perform some link time checks. Those symbols have a fixed 0
- // address that might conflict with real symbols in the object
- // file. As I cannot see a way for absolute symbols to find
- // their way into the debug information, let's just ignore those.
- if (Sym.getFlags() & SymbolRef::SF_Absolute)
+ // The value of some categories of symbols isn't meaningful. For
+ // example common symbols store their size in the value field, not
+ // their address. Absolute symbols have a fixed address that can
+ // conflict with standard symbols. These symbols (especially the
+ // common ones), might still be referenced by relocations. These
+ // relocations will use the symbol itself, and won't need an
+ // object file address. The object file address field is optional
+ // in the DebugMap, leave it unassigned for these symbols.
+ if (Sym.getFlags() & (SymbolRef::SF_Absolute | SymbolRef::SF_Common))
CurrentObjectAddresses[*Name] = None;
else
CurrentObjectAddresses[*Name] = Addr;
More information about the llvm-commits
mailing list