4

I want to optimize some code such that all the functions in string.h will be inlined. I'm on x86_64.

I've tried -O3, -minline-all-stringops and when I do "nm a.out" it shows it is calling the glibc version.

Checking with gcc -S, I see the calls.

What am I missing? There are dozens of #ifdef _SOME_SETTING_ in string.h, and bits/string3.h shows the inline version, but I don't know how to get there.

for example:

$ cat test.c
#include <string.h>

main() {
    char *a, *b;
    strcpy(b,a);
}
/*

When compiled with:

gcc -minline-all-stringops -O6 -I. -S -o test.S test.c

Produces:

    .file   "test.c"
    .text
    .p2align 4,,15
.globl main
    .type   main, @function
main:
.LFB12:
    .cfi_startproc
    subq    $8, %rsp
    .cfi_def_cfa_offset 16
    xorl    %esi, %esi
    xorl    %edi, %edi
    call    strcpy
    addq    $8, %rsp
    .cfi_def_cfa_offset 8
    ret
    .cfi_endproc
.LFE12:
    .size   main, .-main
    .ident  "GCC: (GNU) 4.5.1 20100924 (Red Hat 4.5.1-4)"
    .section    .note.GNU-stack,"",@progbits
*/
tz1
  • 41
  • 3

1 Answers1

1

If a function implementation is not in the header file and in a separate compilation unit, it cannot be inlined unless you have a compiler that can do LTCG.

Sounds like you'll need to write the implementation yourself.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • I can but don't want to and there are inline versions including the implementatino in the header which I thought I indicated (in bits/string3.h included some unknown way in string.h). I need the magic incantation to make string.h use the inlines. – tz1 Mar 03 '11 at 23:33
  • I don't see anything in your code that includes the inlined version. Unless your compilation unit contains the inlined version (usually by including the relevant header file), the compiler can't inline. That's all. – EboMike Mar 03 '11 at 23:36
  • The inlines are in bits/string3.h, but it says I should NOT include it directly. Gcc will define or set things to pick the inlining. – tz1 Mar 04 '11 at 02:10