Author Topic: COMDAT  (Read 11829 times)

Offline sy1234

  • Jr. Member
  • *
  • Posts: 2
COMDAT
« on: March 29, 2011, 08:03:07 PM »
How can I declare/define an elf "comdat" section with nasm?
Thanks.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: COMDAT
« Reply #1 on: March 29, 2011, 10:04:07 PM »
http://www.nasm.us/xdoc/2.09.07/html/nasmdoc6.html#section-6.7

(there's some further information in the "elf" section of the Friendly Manual)

Will this do what you want? Looks like it, but I've never used it. Looks like this applies to individual variables, not to an entire section - so it may not be exactly what you want... If you learn anything, pass it on !

Best,
Frank


Offline sy1234

  • Jr. Member
  • *
  • Posts: 2
Re: COMDAT
« Reply #2 on: March 29, 2011, 10:54:22 PM »
Unfortunately, that's not what I want.

In digging deeper, I guess what I'm interested in is .gnu.linkonce, as described here:

  http://sourceware.org/binutils/docs-2.20/as/Section.html#Section

If you compile any C++ inlined code with gcc (on Linux), like the following:

  struct foo { static void bar() {} };
  int main() { foo::bar(); }

its (gas) listing will include the following:

  .section    .text._ZN3foo3barEv,"axG",@progbits,_ZN3foo3barEv,comdat

that is, a section named ".text._ZN3foo3barEv" that's part of a group that's marked as "comdat" or "linkonce".
I need to reproduce the same thing with nasm.

Thanks.