[PATCH] [mc-coff] Forward Linker Option flags into the .drectve section

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Apr 25 12:16:52 PDT 2013


LGTM.

On 25 April 2013 12:45, Reid Kleckner <rnk at google.com> wrote:
> Phab is down so here's the patch.
>
> On Thu, Apr 25, 2013 at 12:43 PM, Reid Kleckner <rnk at google.com> wrote:
>> On Wed, Apr 24, 2013 at 6:58 PM, Rafael EspĂ­ndola
>> <rafael.espindola at gmail.com> wrote:
>>>> +
>>>> +  // Emit the linker options if present.
>>>> +  if (LinkerOptions) {
>>>
>>> Please use an early return
>>>
>>> if (!LinkerOptions)
>>>  return;
>>
>> Sure.
>>
>>>> +    const MCSection *Sec = getDrectveSection();
>>>> +    Streamer.SwitchSection(Sec);
>>>> +    for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) {
>>>> +      MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i));
>>>> +      for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) {
>>>> +        MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii));
>>>> +        Streamer.EmitBytes(" ");
>>>> +        Streamer.EmitBytes(MDOption->getString());
>>>>
>>>
>>> Is the format documented somewhere we could link to?
>>
>> The .drectve section format, or the module flags metadata format?
>>
>> The .drectve section, which we already use for dllexported symbols, is
>> part of the PE-COFF spec:
>> """
>> A .drectve section consists of a string of text that can be encoded as ANSI or
>> UTF8. If the UTF8 byte order marker (BOM, a three-byte prefix that consists of
>> 0xEF, 0xBB, and 0xBF) is not present, the directive string is
>> interpreted as ANSI.
>> The directive string is a series of linker options that are separated
>> by spaces. Each
>> option contains a hyphen, the option name, and any appropriate attribute. If
>> an option contains spaces, the option must be enclosed in quotes. The .drectve
>> section must not have relocations or line numbers.
>> """
>>
>> One thing that's a little vague is how quotes and backslashes should
>> be escaped.  I'd guess it's the same escaping algorithm used for
>> CreateProcess, since these are flags.
>>
>> Worth linking the doc here, or is the spec kind of an implicit reference?
>>
>> So far as I know, the metadata flags are only documented by
>> implementation and mailing list discussion.  See Daniel's RFC about
>> auto-linking:
>> http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-January/058204.html
>>
>> Is it common to link the mailing list from the source code?
>>
>>>  Index: test/MC/COFF/linker-options.ll
>>>> ===================================================================
>>>> --- /dev/null
>>>> +++ test/MC/COFF/linker-options.ll
>>>> @@ -0,0 +1,28 @@
>>>> +; RUN: llc -O0 -mtriple=i386-pc-win32 -filetype=obj -o - %s | llvm-readobj -s -sd | FileCheck %s
>>>> +
>>>
>>> Please test the output of the assembly file. No need to use -filetype=obj.
>>
>> Sounds good.  For some reason I thought that wouldn't work with COFF,
>> but it works fine.




More information about the llvm-commits mailing list