Skip to main content

[system] ldd - print shared library dependencies

$ whatis ldd
ldd (1)              - print shared library dependencies

ldd có sẵn trên máy bạn vì nó nằm trong package glibc

Từ khóa
shared libraries: hiểu đơn giản hết cỡ thì nó là các library được chương trình load vào khi chạy. (Chi tiết xem ở cuối bài)

Theo man 1 ldd 
ldd prints the shared libraries required by each program or shared library specified on the command line.

Vậy ldd dùng để xem 1 chương trình (hay một library) phụ thuộc (sử dụng) library nào.

Ví dụ:

hvn@archhvn: ~ () $ ldd /usr/bin/ldd
    not a dynamic executable => ldd không dùng thư viện nào
hvn@archhvn: ~ () $ ldd /bin/ls
    linux-vdso.so.1 (0x00007fff2e7fe000)
    libcap.so.2 => /usr/lib/libcap.so.2 (0x00007fd382293000)
    libacl.so.1 => /usr/lib/libacl.so.1 (0x00007fd38208a000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007fd381ce0000)
    libattr.so.1 => /usr/lib/libattr.so.1 (0x00007fd381adb000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fd382497000)
hvn@archhvn: ~ () $ ldd /bin/bash
    linux-vdso.so.1 (0x00007fff003fe000)
    libreadline.so.6 => /usr/lib/libreadline.so.6 (0x00007fbec940a000)
    libncursesw.so.5 => /usr/lib/libncursesw.so.5 (0x00007fbec91a5000)
    libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fbec8fa1000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007fbec8bf7000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fbec9650000)


Shared libraries
are libraries that are loaded by programs when they start. When a shared library is installed properly, all programs that start afterwards automatically use the new shared library. It's actually much more flexible and sophisticated than this, because the approach used by Linux permits you to:
  • update libraries and still support programs that want to use older, non-backward-compatible versions of those libraries;
  • override specific libraries or even specific functions in a library when executing a particular program.
  • do all this while programs are running using existing libraries.
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Chú ý về security (từ man 1 ldd)
   Security
       In  the  usual case, ldd invokes the standard dynamic linker (see ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set to 1,  which causes the linker to display the library dependencies.  Be aware, however, that in some  circumstances,  some  versions  of  ldd  may       attempt  to  obtain  the  dependency information by directly executing the program.  Thus, you should never employ ldd on an untrusted executable, since this may result in the execution of arbitrary code.  A safer alternative when dealing with untrusted executables is:

           $ objdump -p /path/to/program | grep NEEDED

Bài viết thực hiện trên:
$ uname -a
Linux archhvn 3.12.5-1-ARCH #1 SMP PREEMPT Thu Dec 12 12:57:31 CET 2013 x86_64 GNU/Linux

Comments

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG