[PATCH][AsmParser][MC] Allow asm parser to emit elf header flags

Vladimir Medic Vladimir.Medic at imgtec.com
Tue Oct 15 07:53:14 PDT 2013


Hi Rafael,
I have made a small patch that utilizes the methods you defined, and I'd kindly ask you to review it and see if our concept is right. Please note that this is not a complete patch, it's purpose is not to be committed but rather a proof of concept.
1. We have changed your emitMipsHackELFFlags method with emitMipsRelocModel which emits a relocation model info to elf header. There is also a helper method emitMipsELFFlags, which in case of AsmStreamer does nothing, and for ElfStreamer actual value is emitted to the output. The model enumerated values are defined in MipsTargetStreamer. They are meant to be visible from parser since it doesn't need to know which actual output is emitted and should not be aware of elf flags or possible other output values.
2. emitElfHeaderFlags method is added to enable us to emit the command line flags to elf header at the beginning of parsing. The existing methods in AsmPrinter don't get called when llvm-mc is invoked so we introduced a new method in streamer. We are passing MCSubtargetInfo as a parameter since TargetStreamer has no other way to access this information(please correct me if I'm wrong).

There are also things that we need to clarify in order to continue with implementation of the changes that should utilize the new streamer based approach.
1. What is the relation between AsmPrinter and TargetStreamer in the lights of these changes? Is AsmPrinter just a kind of streamer or more likely a wrapper that utilizes TargetStreamer? In later case, it seems that some methods currently existing in MipaAsmParser should be moved to MipsAsmTargetStreamer.
2. As the implementation of TargetStreamer grows, would it make sense to move it to a separate file? Is there any particular reason why you put it in MipsMCTargetDesc.cpp?

Kind regards

Vladimir

________________________________________
From: Rafael EspĂ­ndola [rafael.espindola at gmail.com]
Sent: Saturday, October 05, 2013 6:28 AM
To: Jack Carter
Cc: Vladimir Medic; llvm-commits at cs.uiuc.edu; Jim Grosbach; Rich Fuhler
Subject: Re: [PATCH][AsmParser][MC] Allow asm parser to emit elf header flags

I spent some time reading the code that is already on trunk. It is a
pretty bad violation of the MC design, which is in part why this patch
looks odd.

What needs to happen is


+  MipsMCAsmFlags Flags;

This should be added to the streamer, not the parser. The parser a
really simple layer that driver the streamer. With that, then

  if (IDVal == ".abicalls") {
+    Flags.setRelocationModel(MipsMCAsmFlags::MAF_RM_CPIC);
+    if (Parser.getTok().isNot(AsmToken::EndOfStatement))
+      return Error(Parser.getTok().getLoc(), "unexpected token in directive");
+    return false;
+  }

Should call a emitAbitCalls method on the streamer.

And codegen should not have a   MipsELFStreamer::emitELFHeaderFlagsCG
and a MipsELFStreamer::emitELFHeaderFlagsAsm. That is the entire point
of having MC!

For this patch, at the very minimum you should transform

    EFlags |= ELF::EF_MIPS_CPIC;

to a call to  emitAbitCalls before   if (hasRawTextSupport()) in
emitELFHeaderFlagsCG.

I am sorry I missed emitELFHeaderFlagsCG when it went in. It should
never have happened.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MipsElfFlags.patch
Type: application/octet-stream
Size: 9954 bytes
Desc: MipsElfFlags.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131015/1fe142b9/attachment.obj>


More information about the llvm-commits mailing list