[lld] r190658 - [lld][ELF] Handle multiple weak symbols

Shankar Easwaran shankare at codeaurora.org
Thu Sep 12 21:25:45 PDT 2013


Author: shankare
Date: Thu Sep 12 23:25:44 2013
New Revision: 190658

URL: http://llvm.org/viewvc/llvm-project?rev=190658&view=rev
Log:
[lld][ELF] Handle multiple weak symbols

This handles multiple weak symbols which appear back to back. This fix is needed
which otherwise will lead to symbols getting initialized to arbitrary values.

There was a constructor/destructor test that really triggered this to be fixed
on X86_64.

Adds a test.

Added:
    lld/trunk/test/elf/X86_64/Inputs/multiweaksyms.o
    lld/trunk/test/elf/X86_64/Inputs/weak.s
    lld/trunk/test/elf/X86_64/multi-weak-layout.test
Modified:
    lld/trunk/lib/ReaderWriter/ELF/File.h
    lld/trunk/test/elf/X86_64/Inputs/weak.o

Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=190658&r1=190657&r2=190658&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Thu Sep 12 23:25:44 2013
@@ -428,19 +428,18 @@ public:
           if (previousAtom)
             createEdge(anonAtom, previousAtom,
                        lld::Reference::kindLayoutBefore);
+          // If this is the last atom, lets not create a followon reference.
+          if (anonAtom && (si + 1) != se) {
+            anonFollowedBy = new (_readerStorage) ELFReference<ELFT>(
+                lld::Reference::kindLayoutAfter);
+            anonAtom->addReference(anonFollowedBy);
+          }
         }
 
         ELFDefinedAtom<ELFT> *newAtom = createDefinedAtomAndAssignRelocations(
             symbolName, *sectionName, &*symbol, section, symbolData);
         newAtom->setOrdinal(++_ordinal);
 
-        // If this is the last atom, lets not create a followon reference.
-        if (anonAtom && (si + 1) != se) {
-          anonFollowedBy = new (_readerStorage)
-              ELFReference<ELFT>(lld::Reference::kindLayoutAfter);
-          anonAtom->addReference(anonFollowedBy);
-        }
-
         // If the atom was a weak symbol, lets create a followon reference to
         // the anonymous atom that we created.
         if (anonAtom)

Added: lld/trunk/test/elf/X86_64/Inputs/multiweaksyms.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/multiweaksyms.o?rev=190658&view=auto
==============================================================================
Binary files lld/trunk/test/elf/X86_64/Inputs/multiweaksyms.o (added) and lld/trunk/test/elf/X86_64/Inputs/multiweaksyms.o Thu Sep 12 23:25:44 2013 differ

Modified: lld/trunk/test/elf/X86_64/Inputs/weak.o
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/weak.o?rev=190658&r1=190657&r2=190658&view=diff
==============================================================================
Binary files - no diff available.

Added: lld/trunk/test/elf/X86_64/Inputs/weak.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/Inputs/weak.s?rev=190658&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/Inputs/weak.s (added)
+++ lld/trunk/test/elf/X86_64/Inputs/weak.s Thu Sep 12 23:25:44 2013
@@ -0,0 +1,21 @@
+	.file	"weak.s"
+	.text
+	.p2align 4,,15
+	.globl	test
+	.type	test, @function
+test:
+	ret
+	.size	test, .-test
+	.weak	myfn2
+	.data
+	.align 8
+	.type	myfn2, @object
+	.size	myfn2, 8
+myfn2:
+	.quad	test
+	.weak	myfn1
+	.align 8
+	.type	myfn1, @object
+	.size	myfn1, 8
+myfn1:
+	.quad	test

Added: lld/trunk/test/elf/X86_64/multi-weak-layout.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/multi-weak-layout.test?rev=190658&view=auto
==============================================================================
--- lld/trunk/test/elf/X86_64/multi-weak-layout.test (added)
+++ lld/trunk/test/elf/X86_64/multi-weak-layout.test Thu Sep 12 23:25:44 2013
@@ -0,0 +1,46 @@
+# Test that we are able to layout multiple weak symbols
+# properly
+
+RUN: lld -flavor gnu -target x86_64 %p/Inputs/multiweaksyms.o  \
+RUN: --noinhibit-exec -static -emit-yaml -o %t
+RUN: FileCheck %s -check-prefix=WEAKSYMS < %t
+
+WEAKSYMS:  - ref-name:        [[SYMA:[-a-zA-Z0-9_]+]]
+WEAKSYMS:    type:            data
+WEAKSYMS:    references:      
+WEAKSYMS:      - kind:            layout-after
+WEAKSYMS:        target:          [[SYMB:[-a-zA-Z0-9_]+]]
+WEAKSYMS:  - name:            myfn2
+WEAKSYMS:    scope:           global
+WEAKSYMS:    type:            data
+WEAKSYMS:    merge:           as-weak
+WEAKSYMS:    references:      
+WEAKSYMS:      - kind:            layout-after
+WEAKSYMS:        target:          [[SYMB]]
+WEAKSYMS:  - ref-name:        [[SYMB]]
+WEAKSYMS:    scope:           global
+WEAKSYMS:    type:            data
+WEAKSYMS:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+WEAKSYMS:    references:      
+WEAKSYMS:      - kind:            R_X86_64_64
+WEAKSYMS:        target:          test
+WEAKSYMS:      - kind:            layout-before
+WEAKSYMS:        target:          [[SYMA]]
+WEAKSYMS:      - kind:            layout-after
+WEAKSYMS:        target:          [[SYMC:[-a-zA-Z0-9_]+]]
+WEAKSYMS:  - name:            myfn1
+WEAKSYMS:    scope:           global
+WEAKSYMS:    type:            data
+WEAKSYMS:    merge:           as-weak
+WEAKSYMS:    references:      
+WEAKSYMS:      - kind:            layout-after
+WEAKSYMS:        target:          [[SYMC]]
+WEAKSYMS:  - ref-name:        [[SYMC]]
+WEAKSYMS:    scope:           global
+WEAKSYMS:    type:            data
+WEAKSYMS:    content:         [ 00, 00, 00, 00, 00, 00, 00, 00 ]
+WEAKSYMS:    references:      
+WEAKSYMS:      - kind:            R_X86_64_64
+WEAKSYMS:        target:          test
+WEAKSYMS:      - kind:            layout-before
+WEAKSYMS:        target:          [[SYMB]]





More information about the llvm-commits mailing list