This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Allow output section data commands to take expressions
ClosedPublic

Authored by meadori on Dec 7 2016, 6:24 PM.

Details

Summary

The current implementation of the output section data store commands
can only handle integer literals, but it should really handle arbitrary
expressions [1]. This commit fixes that.

[1] https://sourceware.org/binutils/docs-2.27/ld/Output-Section-Data.html#Output-Section-Data

Diff Detail

Event Timeline

meadori updated this revision to Diff 80707.Dec 7 2016, 6:24 PM
meadori retitled this revision from to [ELF] Allow output section data commands to take expressions.
meadori updated this object.
meadori added a reviewer: ruiu.
meadori added a subscriber: llvm-commits.

Any comments on this one?

ruiu added inline comments.Dec 8 2016, 2:54 PM
ELF/LinkerScript.cpp
855

You want to pass 0 instead of Dot. When this function is called, Dot doesn't have any meaningful value.

meadori updated this revision to Diff 80837.Dec 8 2016, 3:20 PM

Address review feedback.

ruiu accepted this revision.Dec 8 2016, 3:22 PM
ruiu edited edge metadata.

LGTM. Thanks!

This revision is now accepted and ready to land.Dec 8 2016, 3:22 PM
grimar added a subscriber: grimar.Dec 9 2016, 3:31 AM
grimar added inline comments.
test/ELF/linkerscript/data-commands.s
49

It's a bit wierd.
First 3 lines are equal with test above I think ?

# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %tmips64be
# RUN: ld.lld --script %t.script %tmips64be -o %t2
# RUN: llvm-objdump -s %t2 | FileCheck %s --check-prefix=BE

And you share "BE" with it, its very confusing. I think what you wanted to do is use test above and
just add checks:

# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %tmips64be
# RUN: ld.lld --script %t.script %tmips64be -o %t2
# RUN: llvm-objdump -s %t2 | FileCheck %s --check-prefix=BE
# BE:      Contents of section .foo:
# BE-NEXT:   ff11ff11 22ff1122 3344ff11 22334455
# BE-NEXT:   667788
# BE:      Contents of section .bar:
# BE-NEXT:   ff12ff11 22ff1122 3346ff11 22334455
# BE-NEXT:   667788
This revision was automatically updated to reflect the committed changes.

@grimar , you are right. The tests lines should be reworked. Thinko on my part. Fixed in r289278. Thanks for pointing this out!