This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Allow moving location counter backward in some cases.
ClosedPublic

Authored by grimar on Jul 4 2017, 3:49 AM.

Details

Summary
PHDRS {
 text PT_LOAD FLAGS(5); /* R_E */
 data PT_LOAD FLAGS(6); /* RW_ */
 percpu PT_LOAD FLAGS(6); /* RW_ */
 init PT_LOAD FLAGS(7); /* RWE */
 note PT_NOTE FLAGS(0); /* ___ */
}
SECTIONS
{
 . = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000));

 .text : AT(ADDR(.text) - 0xffffffff80000000) {...} :text = 0x9090
 .notes : AT(ADDR(.notes) - 0xffffffff80000000) {...} :text :note
 __ex_table : AT(ADDR(__ex_table) - 0xffffffff80000000) {...} :text = 0x9090
 ...
 .data..percpu 0 : AT(__per_cpu_load - 0xffffffff80000000) { } :percpu
 . = __per_cpu_load + SIZEOF(.data..percpu);
...
}

When trying to assign address 0x0 to .data..percpu LLD fails with
"unable to move location counter backward" error. Though it should be safe to do
because script controls segments via PHDRS command by itself.

This patch suggests to change logic we use currently. I think what we can do instead of
restricting moving counter always is to check that all sections in PT_LOAD are in assending order.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Jul 4 2017, 3:49 AM
grimar updated this revision to Diff 105393.Jul 6 2017, 3:48 AM
  • Removed usused conditions included by mistake.
  • Addressed review comment about comment grammar.
ruiu edited edge metadata.Jul 11 2017, 4:27 PM

Could you give me a program you are trying to link with this patch?

In D34977#805861, @ruiu wrote:

Could you give me a program you are trying to link with this patch?

It is linux kernel. Script is:
https://github.com/torvalds/linux/blob/master/arch/x86/kernel/vmlinux.lds.S

Reproduce file uploaded here:
https://drive.google.com/file/d/0B_OWr6ld9gUmNG4xbW93bDBDWWM/view

ruiu added inline comments.Jul 12 2017, 6:51 AM
ELF/Writer.cpp
1652–1668 ↗(On Diff #105393)

Can you remove this? It seems this is not directly related to the change you want to make.

grimar updated this revision to Diff 106207.Jul 12 2017, 7:09 AM
  • Addressed review comments (removed sections VA's ordering verification logic).
ruiu accepted this revision.Jul 12 2017, 7:13 AM

LGTM

This revision is now accepted and ready to land.Jul 12 2017, 7:13 AM
This revision was automatically updated to reflect the committed changes.