What is the difference between Scrt1.o and crt1.o?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

When I use gcc -no-pie to compile a .c file,
/usr/lib/x86_64-linux-gnu/crt1.o is used with ld.

When I use gcc without -no-pie to compile a .c file,
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o is
used with ld along with the additional option -pie. What is the
difference between Scrt1.o and crt1.o? When the option -pie of ld is
deleted, it still works, why is it so?

If I use -pie with ld, and use crt1.o instead of Scrt1.o, it still
works. So what is the point of switch from crt1.o to Scrt1.o when
-no-pie is removed from gcc options.

Thanks.

# equivalent commands of gcc without -no-pie

/usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet a.c -o a.s
as -o a.o a.s
cmd=(ld
-dynamic-linker
/lib64/ld-linux-x86-64.so.2
-pie
 /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o
 /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
a.o
-lc
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
)
"${cmd[@]}"

# equivalent commands of gcc with -no-pie

/usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet a.c -o a.s
as -o a.o a.s
cmd=(ld
-dynamic-linker
/lib64/ld-linux-x86-64.so.2
/usr/lib/x86_64-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crti.o
a.o
-lc
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
)
"${cmd[@]}"

$ cat a.c
#include <stdio.h>
const char s[] = "Hello World2!";
int main() {
  puts("Hello World!");
  puts(s);
}

-- 
Regards,
Peng



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux