[PATCH] options -ffunction-sections and -fdata-sections

Hi,

This is a patch that implements "-ffunction-sections" and
"-fdata-sections" options.
These options place each functions and data into its own section in the
output file.
Currently it works only for elf format backend, for other object formats
these options are ignored.

This patch is separated for clang tree and llvm tree.

function-data-sections.patch (5.87 KB)

function-data-sections-clang.patch (3.87 KB)

Hello, Sylvere

Currently it works only for elf format backend, for other object formats
these options are ignored.

First of all, please honor the LLVM coding style (or, at least, the
code style of the source files you're modifying).
Second, I belive the approach used is wrong - there is already way to
emit objects into separate sections, which
is used for linkonce objects, you just need to hook in there. No need
to reinvent the wheel :slight_smile:

Anton Korobeynikov wrote:

Hello, Sylvere

Currently it works only for elf format backend, for other object formats
these options are ignored.
    

First of all, please honor the LLVM coding style (or, at least, the
code style of the source files you're modifying).
  

Ok, I have checked this point, I hope it's ok now

Second, I belive the approach used is wrong - there is already way to
emit objects into separate sections, which
is used for linkonce objects, you just need to hook in there. No need
to reinvent the wheel :slight_smile:
  

Thanks for the tip, I've changed my patch using the existing code. But I use different section names than gnu.linkonce when It's not "WeakForLinker"
because gnu.linkonce.* are special sections. (I try to follow GCC section naming for -ffunction-sections/-fdata-sections)

function-data-sections-clang.patch (3.91 KB)

function-data-sections-llvm.patch (4.66 KB)

Hi Sylvere,

I agree that they can’t be happen with linkonce linkage… but this should be handled in the backend, not in the frontend. TargetLoweringObjectFileELF::SelectSectionForGlobal is in charge of picking the section to use of a global, can you put this logic there?

-Chris

Chris Lattner a écrit :

Hi Sylvere,

I agree that they can't be happen with linkonce linkage... but this
should be handled in the backend, not in the frontend.
TargetLoweringObjectFileELF::SelectSectionForGlobal is in charge of
picking the section to use of a global, can you put this logic there?

-Chris

Hi Chris,

Perhaps I don't understand correctly your remark but that's what this
patch does: The function
TargetLoweringObjectFileELF::SelectSectionForGlobal is modified.

There are 2 patchs: 1 for llvm tree and 1 for clang tree.

Aha, I either wildly misread your patch or read an earlier one, sorry about that!

I applied your llvm patch here (with a few changes + testcase):
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20100412/099668.html

and your clang patch here:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20100412/029278.html

Can you write a testcase for the clang part?

Thanks!

-Chris