This is an archive of the discontinued LLVM Phabricator instance.

[clang] Implement support for -defsym assembler option
ClosedPublic

Authored by mgrang on Nov 1 2016, 2:02 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

mgrang updated this revision to Diff 76626.Nov 1 2016, 2:02 PM
mgrang retitled this revision from to [clang] Implement support for --defsym assembler option.
mgrang updated this object.
mgrang added a project: Restricted Project.
mgrang updated this object.Nov 1 2016, 3:14 PM
mgrang added a reviewer: colinl.
mgrang updated this revision to Diff 77089.Nov 7 2016, 1:27 PM

Changed setSymbolValue to use Streamer directly instead of getting it from Parser.

I'm slightly wary of that test, and it would be better to split between driver and defsym features. See mips-ias-Wa.s for the driver test.

Adding Saleem, as he also had some good fiddling on the driver.

I'm not sure how we'll test the asm changes, though. Your test is valid, but we've moved from testing asm in Clang. Are those symbols exported to IR in any form? Global values?

Adding Eric, as he had a go on removing the code tests in Clang.

lib/Driver/Tools.cpp
3118 ↗(On Diff #77089)

This is a bit of a mess, but the -mcpu above is "validated later" because it handles both integrated and non-integrated as, which is still a big deal on ARM world.

Can you try to move it up and see if you can make it work with no-integrated-as, too? To test this, just make sure with clang -v -### that the --defsym is passed to the assembler.

test/Driver/defsym.s
1 ↗(On Diff #77089)

You're going to need -target options here.

25 ↗(On Diff #77089)

Don't put code here, just checking for the values is enough in the driver test.

You may need a new CC1 test with the values.

compnerd requested changes to this revision.Nov 14 2016, 8:19 AM
compnerd edited edge metadata.

I think that we do need some testing for the definition itself propagating correctly. I think that the best way to handle this is to add command line handling for --defsym to llvm-mc and then using that to assemble bits of assembly on the LLVM side rather than the clang side. We could do that first, and then wire that up through to clang in a subsequent change (which this change does).

lib/Driver/Tools.cpp
3118 ↗(On Diff #77089)

I wonder if its better to use A->getOption()->getID() rather than relying on the spelling of the argument. This is definitely not your fault, but we could stem the behavior here.

test/Driver/defsym.s
1 ↗(On Diff #77089)

I dont think that a -target is necessary. The flag should go through on any target, so the host is as good as a specific target.

25 ↗(On Diff #77089)

As @rengolin mentioned, please don't add assembly in the driver tests. They are meant to test just the argument handling in the driver.

This revision now requires changes to proceed.Nov 14 2016, 8:19 AM
rengolin added inline comments.Nov 14 2016, 9:07 AM
test/Driver/defsym.s
1 ↗(On Diff #77089)

right, I made that comment before the one below. I agree, no --target and no asm code. :)

@rengolin @compnerd Thanks for your comments/suggestions. I will address them.

Thanks,
Mandeep

mgrang added inline comments.Nov 17 2016, 4:39 PM
lib/Driver/Tools.cpp
3118 ↗(On Diff #77089)

@compnerd Since this is a -Wa option here's what we have:

A->getOption().getID() gives options::OPT_Wa_COMMA
A->getOption().getValue gives StringRef("--defsym")
A->getOption().getName() gives Wa,

So I guess there is no easy way to get the option for a -Wa flag since the value is of type StringRef.

mgrang added inline comments.Nov 18 2016, 10:30 AM
lib/Driver/Tools.cpp
3118 ↗(On Diff #77089)

@rengolin I see that the --defsym option is already being passed to the non-integrated-as.

clang -### a.s -no-integrated-as -c -Wa,--defsym,abc=1 -v
"/usr/bin/as" "--defsym" "abc=1" "-o" "a.o" "a.s"

mgrang updated this revision to Diff 78565.Nov 18 2016, 11:52 AM
mgrang edited edge metadata.
mgrang marked an inline comment as done.Nov 18 2016, 11:52 AM
mgrang added inline comments.
test/Driver/defsym.s
25 ↗(On Diff #77089)

@rengolin Where should I add the cc1as test with the values?

compnerd accepted this revision.Nov 28 2016, 8:31 PM
compnerd edited edge metadata.
compnerd added inline comments.
include/clang/Driver/CC1Options.td
748 ↗(On Diff #78565)

I think that using a single dash would be nicer as it would fit in well with the rest of the options.

This revision is now accepted and ready to land.Nov 28 2016, 8:31 PM
mgrang updated this revision to Diff 79806.Nov 30 2016, 1:34 PM
mgrang retitled this revision from [clang] Implement support for --defsym assembler option to [clang] Implement support for -defsym assembler option.
mgrang updated this object.
mgrang edited edge metadata.

Changed --defsym to -defsym as per @compnerd 's suggestion.

mgrang marked an inline comment as done.Nov 30 2016, 1:35 PM
rengolin accepted this revision.Dec 1 2016, 7:20 AM
rengolin edited edge metadata.

Sorry, fell out of my radar. LGTM.

This revision was automatically updated to reflect the committed changes.
tra added a subscriber: tra.Dec 1 2016, 11:46 AM
tra added inline comments.
cfe/trunk/test/Driver/defsym.s
14–22

These need -o /dev/null, otherwise compiler will attempt to create a file which is not something we want here.

Fixed in r288406.

mgrang added inline comments.Dec 1 2016, 4:53 PM
cfe/trunk/test/Driver/defsym.s
14–22

Thanks @tra