What does my gcc-compiled program depend on? [closed]

I’m trying to understand the dependencies of a C program, and I’m slowly realizing that gcc main.c -o main is hiding a lot of details.

Here’s my experiment (ubuntu-wsl-x64):

As you can see, my program is linked to

  • The GNU libc (through a symbolic link libc.so.6)
  • The GNU linker (ld-linux-x86-64.so.2)
  • A weird dynamic library (linux-vdso.so.1)

To my understanding, the linux-vdso.so.1 will implement certain libc API to improve the speed of certain system calls.

Questions:

  1. Why is linux-vdso.so.1 is not already included in libc?
  2. Why is ld dynamically linked to my executable? Is it used at runtime?
  3. To my understanding, my program also should depend on libgcc and crt0 are they linked statically?
  4. There must be a -I hidden so the program can see the libc header file. Am I correct? I so, where are they?
  5. Am I missing something else?

Thanks, kind strangers.

16

As you can see, my program is linked to

  • The GNU libc (through a symbolic link libc.so.6)

Yes.

  • The GNU linker (ld-linux-x86-64.so.2)

No. That is not the GNU linker (ld). It is the Linux dynamic linker. It serves as the standard ELF program loader on Linux. Every ELF executable needs such a loader in order to run.

  • A weird dynamic library (linux-vdso.so.1)

Sort of. “vdso” is an initialism of “virtual dynamic shared object”. This particular one is provided to every process by the Linux kernel, and the C standard library relies on it for various kernel services. It is not bundled into libc because for all intents and purposes, it is part of the kernel.

  1. To my understanding, my program also should depend on libgcc and crt0 are they linked statically?

Some programs compiled with GCC depend on libgcc. Others don’t. It depends on the program. libgcc could be linked statically — GCC has a command-line option for that — but if you didn’t ask for that then it probably isn’t.

I don’t know what crt0 is, maybe this: https://en.wikipedia.org/wiki/Crt0? As far as I know, that does not take the form of a separate shared library, so ldd would not tell you about it.

There must be a -I hidden so the program can see the libc header file. Am I correct? I so, where are they?

No, you are not correct. GCC has a default search path for include files that includes the headers for the standard library with which it is integrated. You use a -I option to add directories to that search path, but you don’t need one for the standard library headers, or for others installed in that path (and what a pain it would be if you did!). Gcc will tell you what the default search path is if you ask it.

  1. Am I missing something else?

Probably many things, given the nature of the specific questions posed. It’s hard to say which of them may actually be of interest to you in this context, and likely impossible to fit them into the scope of an SO answer.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật