This is an archive of the discontinued LLVM Phabricator instance.

[ELF] implement --warn-common/--no-warn-common
ClosedPublic

Authored by grimar on Mar 9 2016, 9:52 AM.

Details

Summary

-warn-common

Warn when a common symbol is combined with another common symbol
or with a symbol definition.  Unix linkers allow  this  somewhat
sloppy  practice, but linkers on some other operating systems do
not.  This option allows you to  find  potential  problems  from
combining global symbols.

This should fix the the https://llvm.org/bugs/show_bug.cgi?id=26737

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 50153.Mar 9 2016, 9:52 AM
grimar retitled this revision from to [ELF] implement --warn-common/--no-warn-common.
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
ruiu added inline comments.Mar 9 2016, 10:00 AM
ELF/Config.h
77 ↗(On Diff #50153)

Remove = false.

ELF/Symbols.cpp
145–152 ↗(On Diff #50153)

I wouldn't add new code to this function. Instead, please try to make this a new function or refactor this function to make it shorter.

grimar added inline comments.Mar 9 2016, 11:20 AM
ELF/Symbols.cpp
145–152 ↗(On Diff #50153)

My version of refactor is here: http://reviews.llvm.org/D18004

grimar updated this revision to Diff 50411.Mar 11 2016, 3:10 AM
  • Rebased after refactoring
grimar updated this revision to Diff 50412.Mar 11 2016, 3:12 AM
  • Addressed review comment
ruiu edited edge metadata.Mar 11 2016, 10:47 AM

What about the Joerg's comment? Doesn't this always warn on two common symbol who have the same name?

In D17998#373261, @ruiu wrote:

What about the Joerg's comment? Doesn't this always warn on two common symbol who have the same name?

Yea, I answered already via llvm-mails, but will duplicate answer here for history of patch.
Current logic always warn about such symbols. I did that intentionaly because gold do the same,
consider 2 files:

test.s:

.globl _start
_start:

.type arr,@object
.comm arr,4,4

test2.s:

.type arr,@object
.comm arr,4,4

So 2 commons have the same size and gold produces a warning in that case:
++ /home/LLVM/build/bin/llvm-mc -filetype=obj test.s -o test.o
++ /home/LLVM/build/bin/llvm-mc -filetype=obj test2.s -o test2.o
++ gold -warn-common test.o test2.o -o test
gold: warning: test2.o: multiple common of 'arr'
gold: test.o: previous definition here

ruiu accepted this revision.Mar 12 2016, 6:44 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Mar 12 2016, 6:44 PM
emaste added a subscriber: emaste.Mar 13 2016, 9:11 PM
This revision was automatically updated to reflect the committed changes.