[patch] Correctly set the comdat symbol on COFF

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Jun 5 13:55:13 PDT 2014


On 5 June 2014 16:40, Reid Kleckner <rnk at google.com> wrote:
> This seems wrong for associative comdats.  Won't the comdat symbol
> necessarily be in a different section?

Not if I am reading the spec correctly. It looks like this situation
will look like:

* Section foo has the following symbols in order:
  * The symbol foo, which has an auxiliary symbol with a Seltion field
with IMAGE_COMDAT_SELECT_ASSOCIATIVE and a Number field pointing to
the associated section.
  * The comdat symbol, which can be anything, lets say bar

The associated section can have any name, lets say zed. It has the
following symbols
* The symbol zed. The only constraint being that it is not itself associative.
* The comdat symbol, with can be any other symbol, bah for example.

In summary, each section has a different comdat symbol. The link of
associative sections is independent of the comdat, except that they
probably cannot have the some comdat, otherwise we would be asking the
linker to keep both and discard one at the same time :-)

> Also, I ran into some problems with our assembly parsing:
>
> $ cat t.cpp
> int foo();
> template <typename T> struct Foo { static int x; };
> template <typename T> int Foo<T>::x = foo();
> int main() { return Foo<int>::x; }
>
> $ clang -c t.cpp -S -o -  | llvm-mc -o t.s
> <stdin>:47:37: error: associated section must be a COMDAT section
>         .section        .CRT$XCU,"rd",associative .bss,"?x@?$Foo at H@@2HA"

It is probably independent, but I will take a look.

Cheers,
Rafael



More information about the llvm-commits mailing list