[llvm-bugs] [Bug 38921] New: .weak directive ignored if symbol is not already defined

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 12 19:23:27 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38921

            Bug ID: 38921
           Summary: .weak directive ignored if symbol is not already
                    defined
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: joel at jms.id.au
                CC: llvm-bugs at lists.llvm.org

When building the powerpc linux kenrel with clang, a symbol is not correctly
marked weak in the ELF which breaks the build when linking the kernel image:

 $ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
 0000000000000058 g       .text  0000000000000000 _zimage_start

 ld: arch/powerpc/boot/wrapper.a(crt0.o): in function '_zimage_start':
 (.text+0x58): multiple definition of '_zimage_start';
 arch/powerpc/boot/pseries-head.o:(.text+0x0): first defined here

Clang requires the .weak directive to appear after the symbol is
declared. The binutils manual says:

 This directive sets the weak attribute on the comma separated list of
 symbol names. If the symbols do not already exist, they will be
 created.

So it appears this is different with clang. The only reference I could
see for this was an OpenBSD mailing list post[1].

Changing it to be after the declaration fixes building with Clang, and 
still works with GCC.

 $ objdump -t arch/powerpc/boot/crt0.o |grep _zimage_start$
 0000000000000058  w      .text 0000000000000000 _zimage_start

[1] https://groups.google.com/forum/#!topic/fa.openbsd.tech/PAgKKen2YCY


Is this intentional? Can we change the behaviour to match the binutils linker?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180913/87890f74/attachment.html>


More information about the llvm-bugs mailing list