LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 36716 - Find the "best" order for local symbols
Summary: Find the "best" order for local symbols
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: ELF (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-13 16:31 PDT by Rafael Ávila de Espíndola
Modified: 2018-04-11 02:25 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2018-03-13 16:31:46 PDT
There is an interesting discussion at generic-abi@googlegroups.com about the order of local symbols.

The ELF spec doesn't say anything about it, so we can try to figure out what is the most convenient for linkers and consumers

Linking
----------------------------------
        .file "file1"
local1:
        .global hidden1
        .hidden hidden1
hidden1:
---------------------------------
And
---------------------------------
        .file "file2"
local2:
        .global hidden2
        .hidden hidden2
hidden2:
--------------------------------

The results are

lld: local1, local2, hidden1, hidden2
bfd: file1, corrupted file2?, hidden1, hidden2
gold: file1, local1, file2, local2, hidden1, hidden2

Gold's output has the advantage that one can map the original local symbols to a file. The exception being that the hidden symbols show up as being from file2 (one can still check the visibility to tell the difference).

Two orders that might be ever better are

* hidden1, hidden2, file1, local2, file2, local2
* file1, local1, hidden1, file2, local2, hidden2

The first one has the advantage of making it easy to find out the file of local symbols.

The second one has the advantage of specifying where the hidden symbols came from.
Comment 1 George Rimar 2018-03-15 07:59:42 PDT
Do you have URL for discussion topic you mentioned?
Comment 2 Rafael Ávila de Espíndola 2018-03-15 19:09:19 PDT
(In reply to George Rimar from comment #1)
> Do you have URL for discussion topic you mentioned?

https://groups.google.com/forum/#!topic/generic-abi/tSU1wY1xyY8
Comment 3 George Rimar 2018-04-02 04:41:49 PDT
(In reply to Rafael Ávila de Espíndola from comment #0)
> Two orders that might be ever better are
> 
> * hidden1, hidden2, file1, local2, file2, local2
> * file1, local1, hidden1, file2, local2, hidden2
> 
> The first one has the advantage of making it easy to find out the file of
> local symbols.
> 
> The second one has the advantage of specifying where the hidden symbols came
> from.

The second looks nice, but LLD does not keep file symbols currently.
If it makes sense to know where are locals came from, maybe it worth just to
change -cref to print them out?
Comment 4 Rafael Ávila de Espíndola 2018-04-02 16:33:19 PDT
(In reply to George Rimar from comment #3)
> (In reply to Rafael Ávila de Espíndola from comment #0)
> > Two orders that might be ever better are
> > 
> > * hidden1, hidden2, file1, local2, file2, local2
> > * file1, local1, hidden1, file2, local2, hidden2
> > 
> > The first one has the advantage of making it easy to find out the file of
> > local symbols.
> > 
> > The second one has the advantage of specifying where the hidden symbols came
> > from.
> 
> The second looks nice, but LLD does not keep file symbols currently.
> If it makes sense to know where are locals came from, maybe it worth just to
> change -cref to print them out?

The tool we have uses just .o files, so we would have to write it there. Adding file symbols to lld should be simple, no?
Comment 5 George Rimar 2018-04-03 07:39:47 PDT
(In reply to Rafael Ávila de Espíndola from comment #4)
> (In reply to George Rimar from comment #3)
> > (In reply to Rafael Ávila de Espíndola from comment #0)
> > > Two orders that might be ever better are
> > > 
> > > * hidden1, hidden2, file1, local2, file2, local2
> > > * file1, local1, hidden1, file2, local2, hidden2
> > > 
> > > The first one has the advantage of making it easy to find out the file of
> > > local symbols.
> > > 
> > > The second one has the advantage of specifying where the hidden symbols came
> > > from.
> > 
> > The second looks nice, but LLD does not keep file symbols currently.
> > If it makes sense to know where are locals came from, maybe it worth just to
> > change -cref to print them out?
> 
> The tool we have uses just .o files, so we would have to write it there.
> Adding file symbols to lld should be simple, no?

Should be. That will increase the output size by some amount.
I can do a patch to enable file symbols and check the clang binary difference,
for start.
Comment 6 George Rimar 2018-04-11 02:25:31 PDT
r329787