The freestanding flag should make gcc forget about special function names
and, specifically about the main() entry point. Anyway, gcc generates
different code for two source files that differ only in the name of a function,
beeing this name "main" in one of them.

When one of the functions in the source file is named main the compiler
generates three additional instructions for stack alignment. These
instructions are at offsets 0x05, 0x09 and 0x0c in the following example:

00000005 <main>:
   5:   8d 4c 24 04             lea    0x4(%esp),%ecx
   9:   83 e4 f0                and    $0xfffffff0,%esp
   c:   ff 71 fc                pushl  -0x4(%ecx)
   f:   55                      push   %ebp
  10:   89 e5                   mov    %esp,%ebp
  12:   51                      push   %ecx

The same file with the function name changed produces the following code:

00000005 <start>:
   5:   55                      push   %ebp
   6:   89 e5                   mov    %esp,%ebp

The following line was used for both cases:

gcc -m32 -ffreestanding -c -I../include -o task_test.o task_test.c -Wall
-Wextra -Werror


-- 
           Summary: Detection of main() as an entry point when given -
                    ffreestanding
           Product: gcc
           Version: 4.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dgodas at gmail dot com
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42523

Reply via email to