This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Add support for .secidx directives
ClosedPublic

Authored by timurrrr on Dec 19 2013, 12:56 PM.

Details

Summary

This is extracted from D2232, i.e. needed to generate line table information.

Diff Detail

Event Timeline

Are these llvm extensions to the gas syntax? If so, please document
them in docs/Extensions.rst.

rafael added inline comments.Dec 19 2013, 1:28 PM
lib/MC/MCAssembler.cpp
963 ↗(On Diff #6197)

Data.size() is always 4. The initialization use 4 zero bytes, so this always returns false, no? If so, why is this part of the relaxation?

Is gas unable to do this sort of thing? If it is able it'd be good to copy the syntax from there.

test/MC/COFF/secref.s
8 ↗(On Diff #6197)

What about cross section relocations?

test/MC/COFF/static_offset.s
15 ↗(On Diff #6197)

If you could explain the numbers here in a comment it would be appreciated.

timurrrr updated this revision to Unknown Object (????).Dec 20 2013, 4:43 AM

Mostly addressed the review comments (questions to follow).

Re: gas - I'm not very familiar with it, but I couldn't find any equivalent of .secref and .offset there.

Also added some docs (to be tried with doxygen, "compiling...").

Re: gas - was looking here https://sourceware.org/binutils/docs/as/Pseudo-Ops.html

lib/MC/MCAssembler.cpp
963 ↗(On Diff #6197)

Data.size() is always 4. The initialization use 4 zero bytes, so this always returns false, no?

Yeah - good catch.
I've updated the code accordingly.

If so, why is this part of the relaxation?

I'm not very familiar with the code, so might be doing this wrong.
Do you recommend to move writing the actual bytes of the AddrDelta?
If so, where do this belongs?

test/MC/COFF/secref.s
8 ↗(On Diff #6197)

Added more tests

test/MC/COFF/static_offset.s
15 ↗(On Diff #6197)

OK, done.
I've also one ret rather three nops as in real-world examples .offset will likely be 4-byte aligned.

rafael added inline comments.Dec 20 2013, 7:37 AM
lib/MC/MCAssembler.cpp
947 ↗(On Diff #6209)

Since the size is fixed, this shouldn't need to be part of the relaxation.

Relaxation exits for things that can change size depending on where other stuff is. For example, a short branch can become a long one and a uleb might need another byte if things more far apart.

What prevents this from being just a data fragment with a relocation to get the correct value?

Follow how llvm-mc implements:


foo:

.zero 4
.zero 4

bar:

zed = bar - foo

2013/12/20 Rafael Ávila de Espíndola <rafael.espindola@gmail.com>:

Comment at: lib/MC/MCAssembler.cpp:947
@@ -939,1 +946,3 @@

+bool MCAssembler::relaxCoffStaticOffsetFragment(

+ MCAsmLayout &Layout, MCCoffStaticOffsetFragment &LDF) {

Since the size is fixed, this shouldn't need to be part of the relaxation.

Relaxation exits for things that can change size depending on where other stuff is. For example, a short
branch can become a long one and a uleb might need another byte if things more far apart.

Sorry, I am still very unfamiliar with the MC part of the codebase, I
mostly worked on the Clang part last year.
Thanks for the clarification, I've also looked at the code and I think
now I have at least a vague idea of what relaxations are :)

What prevents this from being just a data fragment with a relocation to get the correct value?

It's just that I'm not familiar with the codebase.

Follow how llvm-mc implements:


foo:

.zero 4
.zero 4

bar:

zed = bar - foo

Thanks for the pointer, looking.

In fact, I think I can just use

.int To-From

instead of

.offset from From to To

I'll reduce the patch accordingly soon.
Thanks a lot for the pointer!

timurrrr updated this revision to Unknown Object (????).Dec 20 2013, 10:01 AM

Removed the .offset directive part as it's indeed not needed.

Also, renamed "section reference" to "section index".

rnk accepted this revision.Dec 20 2013, 10:07 AM

LGTM

Should I wait for Eric to review?

rnk added a comment.Dec 20 2013, 10:15 AM

No need to wait, post-commit should be fine. This seems pretty obviously good, unless there's some gas directive we could be reusing.

rafael accepted this revision.Dec 20 2013, 10:18 AM

LGTM too.

timurrrr closed this revision.Dec 20 2013, 10:20 AM

Cool!
r197826, thanks for the review!