This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Do not add start and end symbols in case they are defined in linker script
ClosedPublic

Authored by evgeny777 on Aug 11 2016, 6:01 AM.

Details

Reviewers
ruiu
Summary

Without this patch, the following script triggers link error

SECTIONS {
   .init_array : { __init_array_start = .; *(.init_array) __init_array_end = .; }
}

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 67680.Aug 11 2016, 6:01 AM
evgeny777 retitled this revision from to [ELF] Do not add start and end symbols in case they are defined in linker script.
evgeny777 updated this object.
evgeny777 added a reviewer: ruiu.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, emaste and 2 others.
ruiu edited edge metadata.Aug 11 2016, 2:22 PM

This change seems too subtle. Why don't you not call addStartEndSymbols if Scripts->HasContents?

I thought it would make sense to add those symbols if linker script does not provide them for some reason. For example .init_array can be an orphan section, right? Also I wonder what would happen if I define __init_array_start somewhere in my program.

ruiu added a comment.Aug 11 2016, 2:37 PM

Ah, okay, so this change is not really specific to the linker script, but to not define _start/_end symbols if there are already definitions. You want to add a comment about that.

ELF/Writer.cpp
855

Looks like this is getting unnecessarily complicated. Two stages of lambdas? Can you simplify this function if you rewrite it?

evgeny777 updated this revision to Diff 67811.Aug 12 2016, 2:50 AM
evgeny777 edited edge metadata.
evgeny777 removed rL LLVM as the repository for this revision.

Addressed review comments

evgeny777 updated this revision to Diff 67816.Aug 12 2016, 3:30 AM

Simplified

ruiu accepted this revision.Aug 12 2016, 2:13 PM
ruiu edited edge metadata.

LGTM

ELF/Writer.cpp
524

Is Required a good name? Maybe I'd name this simply addSynthetic and add a comment to describe its semantics (defines a symbol unless there's already a defined symbol with the same name.)

This revision is now accepted and ready to land.Aug 12 2016, 2:13 PM
evgeny777 closed this revision.Aug 15 2016, 12:32 AM