I have a library with debug symbols, and I do the following to extract function names:
$ objdump -S -D library_name.so > library_name.asm
$ grep -rn ">:" library_name.asm
This gives me what I want:
3101:0000000000002190 <memset#plt>:
3106:00000000000021a0 <close#plt>:
but seems a bit awkward ... Is there a better way to achieve this?
I think the utility you're looking for is nm:
It collects all the symbols, both static and dynamic, defined in a library or any ELF file.
The output looks like this:
000000ec T main
000003f0 a REG_HID0
000003f1 a REG_HID1
00000ec4 T RSA_bigint_add
000009e0 T RSA_bigint_clear
00000a0c T RSA_bigint_cmp
00000dd8 T RSA_bigint_gen
00000aa4 T RSA_bigint_get_bitlength
000010f4 T RSA_bigint_intmul
00000c20 T RSA_bigint_lshift
00001330 T RSA_bigint_mod
00001470 T RSA_bigint_modexp
0000142c T RSA_bigint_modmul
0000120c T RSA_bigint_mul
00000aec T RSA_bigint_rshift
00001024 T RSA_bigint_sub
00000238 T RSA_check_data_with_certificate
00000180 T RSA_check_signature
000002d0 T RSA_x509_get_field
000003a4 T RSA_x509_get_int
000008f8 T RSA_x509_parse_certificate
0000042c T RSA_x509_parse_PKI
000007d8 T RSA_x509_parse_signature
0000057c T RSA_x509_parse_tbscertificate
Related
on macOS:
nm -g debug/build/lib/libtaos.1.dylib
shows, that not only functions declared in taos.h are exported in dynamic library, but also internal functions, which is not elegant.
I would say this operation might cause some potential security vulnerability in target machine.
0000000000384ec0 T _vnodeProcessQueryMsg
0000000000387750 T _vnodeProcessSyncMsg
0000000000381360 T _vnodeProcessWriteMsg
0000000000385b40 T _vnodeProposeCommitOnNeed
0000000000385ea0 T _vnodeProposeWriteMsg
000000000037dd60 T _vnodeQueryClose
000000000037dcf0 T _vnodeQueryOpen
000000000037dd30 T _vnodeQueryPreClose
00000000003856a0 T _vnodeRedirectRpcMsg
000000000037f320 T _vnodeResetLoad
000000000037d440 T _vnodeRollback
000000000037c3a0 T _vnodeSaveInfo
00000000003800e0 T _vnodeScheduleTask
000000000037c200 T _vnodeShouldCommit
000000000037c320 T _vnodeShouldCommitOld
000000000037d350 T _vnodeShouldRollback
0000000000389ee0 T _vnodeSnapRead
0000000000389e20 T _vnodeSnapReaderClose
0000000000389cd0 T _vnodeSnapReaderOpen
000000000038aee0 T _vnodeSnapWrite
000000000038aa80 T _vnodeSnapWriterClose
000000000038a8f0 T _vnodeSnapWriterOpen
00000000003793b0 T _vnodeStart
00000000003793d0 T _vnodeStop
00000000003885f0 T _vnodeSyncCheckTimeout
0000000000388580 T _vnodeSyncClose
000000000037d310 T _vnodeSyncCommit
0000000000387c90 T _vnodeSyncOpen
0000000000388510 T _vnodeSyncPostClose
0000000000388400 T _vnodeSyncPreClose
0000000000388320 T _vnodeSyncStart
000000000037c180 T _vnodeUpdCommitSched
00000000003855e0 T _vnodeUpdateMetaRsp
000000000037bde0 T _vnodeValidateTableHash
000000000037fcc0 T _vnode_done_commit
000000000037fca0 T _vnode_wait_commit
0000000000441c70 T _voteGrantedCreate
0000000000441d70 T _voteGrantedDestroy
0000000000441e20 T _voteGrantedMajority
00000000004420f0 T _voteGrantedReset
0000000000441da0 T _voteGrantedUpdate
0000000000441e40 T _voteGrantedVote
00000000004422e0 T _votesRespondAdd
0000000000442130 T _votesRespondCreate
00000000004421d0 T _votesRespondDestory
I'm trying to compile the PCRE library into a testing executable.
The documentation states that running Make and then configure should generate the library.
In the PCRE source directory:
Make
./configure
gcc -o test test.c -L . -lpcre
However the following error returns:
/usr/bin/ld: cannot find -pcre
collect2: error: ld returned 1 exit status
Note: I've also tried flag -libpcre. I was able to sucessfully run this on MacOS (seperately compiled but same library source code and same testiing source code).
Directory Contents:
132html pcre16_globals.c
aclocal.m4 pcre16_jit_compile.c
AUTHORS pcre16_maketables.c
ChangeLog pcre16_newline.c
CheckMan pcre16_ord2utf16.c
CleanTxt pcre16_printint.c
cmake pcre16_refcount.c
CMakeLists.txt pcre16_string_utils.c
compile pcre16_study.c
config-cmake.h.in pcre16_tables.c
config.guess pcre16_ucd.c
config.h pcre16_utf16_utils.c
config.h.generic pcre16_valid_utf16.c
config.h.in pcre16_version.c
config.log pcre16_xclass.c
config.status pcre32_byte_order.c
config.sub pcre32_chartables.c
configure pcre32_compile.c
configure.ac pcre32_config.c
COPYING pcre32_dfa_exec.c
depcomp pcre32_exec.c
Detrail pcre32_fullinfo.c
dftables.c pcre32_get.c
doc pcre32_globals.c
HACKING pcre32_jit_compile.c
INSTALL pcre32_maketables.c
install-sh pcre32_newline.c
libpcre16.pc pcre32_ord2utf32.c
libpcre16.pc.in pcre32_printint.c
libpcre32.pc pcre32_refcount.c
libpcre32.pc.in pcre32_string_utils.c
libpcrecpp.la pcre32_study.c
libpcrecpp_la-pcrecpp.lo pcre32_tables.c
libpcrecpp_la-pcrecpp.o pcre32_ucd.c
libpcrecpp_la-pcre_scanner.lo pcre32_utf32_utils.c
libpcrecpp_la-pcre_scanner.o pcre32_valid_utf32.c
libpcrecpp_la-pcre_stringpiece.lo pcre32_version.c
libpcrecpp_la-pcre_stringpiece.o pcre32_xclass.c
libpcrecpp.pc pcre_byte_order.c
libpcrecpp.pc.in pcre_chartables.c
libpcre.la pcre_chartables.c.dist
libpcre_la-pcre_byte_order.lo pcre_compile.c
libpcre_la-pcre_byte_order.o pcre-config
libpcre_la-pcre_chartables.lo pcre_config.c
libpcre_la-pcre_chartables.o pcre-config.in
libpcre_la-pcre_compile.lo pcrecpparg.h
libpcre_la-pcre_compile.o pcrecpparg.h.in
libpcre_la-pcre_config.lo pcrecpp.cc
libpcre_la-pcre_config.o pcrecpp.h
libpcre_la-pcre_dfa_exec.lo pcrecpp_internal.h
libpcre_la-pcre_dfa_exec.o pcrecpp_unittest
libpcre_la-pcre_exec.lo pcrecpp_unittest.cc
libpcre_la-pcre_exec.o pcrecpp_unittest-pcrecpp_unittest.o
libpcre_la-pcre_fullinfo.lo pcredemo
libpcre_la-pcre_fullinfo.o pcredemo.c
libpcre_la-pcre_get.lo pcre_dfa_exec.c
libpcre_la-pcre_get.o pcre_exec.c
libpcre_la-pcre_globals.lo pcre_fullinfo.c
libpcre_la-pcre_globals.o pcre_get.c
libpcre_la-pcre_jit_compile.lo pcregexp.pas
libpcre_la-pcre_jit_compile.o pcre_globals.c
libpcre_la-pcre_maketables.lo pcregrep
libpcre_la-pcre_maketables.o pcregrep.c
libpcre_la-pcre_newline.lo pcregrep-pcregrep.o
libpcre_la-pcre_newline.o pcre.h
libpcre_la-pcre_ord2utf8.lo pcre.h.generic
libpcre_la-pcre_ord2utf8.o pcre.h.in
libpcre_la-pcre_refcount.lo pcre_internal.h
libpcre_la-pcre_refcount.o pcre_jit_compile.c
libpcre_la-pcre_string_utils.lo pcre_jit_test.c
libpcre_la-pcre_string_utils.o pcre_maketables.c
libpcre_la-pcre_study.lo pcre_newline.c
libpcre_la-pcre_study.o pcre_ord2utf8.c
libpcre_la-pcre_tables.lo pcreposix.c
libpcre_la-pcre_tables.o pcreposix.h
libpcre_la-pcre_ucd.lo pcre_printint.c
libpcre_la-pcre_ucd.o pcre_refcount.c
libpcre_la-pcre_valid_utf8.lo pcre_scanner.cc
libpcre_la-pcre_valid_utf8.o pcre_scanner.h
libpcre_la-pcre_version.lo pcre_scanner_unittest
libpcre_la-pcre_version.o pcre_scanner_unittest.cc
libpcre_la-pcre_xclass.lo pcre_scanner_unittest-pcre_scanner_unittest.o
libpcre_la-pcre_xclass.o pcre_stringpiece.cc
libpcre.pc pcre_stringpiece.h
libpcre.pc.in pcre_stringpiece.h.in
libpcreposix.la pcre_stringpiece_unittest
libpcreposix_la-pcreposix.lo pcre_stringpiece_unittest.cc
libpcreposix_la-pcreposix.o pcre_stringpiece_unittest-pcre_stringpiece_unittest.o
libpcreposix.pc pcre_string_utils.c
libpcreposix.pc.in pcre_study.c
libtool pcre_tables.c
LICENCE pcretest
ltmain.sh pcre_test.c
m4 pcretest.c
Makefile pcretest-pcre_printint.o
Makefile.am pcretest-pcretest.o
Makefile.in pcre_ucd.c
makevp.bat pcre_valid_utf8.c
makevp_c.txt pcre_version.c
makevp_l.txt pcre_xclass.c
missing perltest.pl
NEWS PrepareRelease
NON-AUTOTOOLS-BUILD README
NON-UNIX-USE RunGrepTest
pcre16_byte_order.c RunTest
pcre16_chartables.c RunTest.bat
pcre16_compile.c sljit
pcre16_config.c stamp-h1
pcre16_dfa_exec.c test.c
pcre16_exec.c testdata
pcre16_fullinfo.c ucp.h
pcre16_get.c
Try -lpcre not -libpcre when you link. -l assumes the lib prefix and takes the name of the lib so -lpcre looks for libpcre
I have to build a shared library using another static library. In that static library there are some function calls that are undefined in nm output. I want to remove those symbols, by getting the object file. I cannot delete whole object file, as some part of it is used. Is there any way of doing that.
nm output
request.o:
U CLR_SECURE_MEM_START_ADDR //want to remove
U clrSMEMAlloc //want to remove
U clrSMEMCopy //want to remove
U clrSMEMFree //want to remove
U clrSMEMSet //want to remove
00000000 T copyBuffer
00000000 T copyParameter
00000000 T copyRequest
00000000 T freeParameter
00000000 T freeRequest
00000000 T getLinkFromRequest
U _gp_disp
00000000 T initializeRequest
00000000 T initializeRequestQueue
U isClrSMEMBuffer
00000000 T isParamInSharedMem
00000000 T isRequestInSharedMem
00000004 b RequestQueue
00000000 b RequestQueueHead
U strlen
00000000 T verifyParameter ////want to keep
00000000 T verifyParameterType
00000000 T verifyParameterTypes
00000000 T verifyRequestParameters
I don't have the source of this object file, so I don't know the prototype of the functions that I want to remove. If I had the source I could have written dummy definitions.
P.S
The library that I had was broken. Thats why I had undefined references.
According to Michael Walz's comment, I didn't needed to strip the .o file. I just had to create a file depend.c. Put a definition for those functions which were undefined. Then build it
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libdepend
LOCAL_SRC_FILES := src/depend.cpp
LOCAL_CFLAGS := -DCLR_INTERAPTIV_I7 -DCLR_INTERAPTIV -v
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../RIP/include/ $(LOCAL_PATH)/../../../hardware/libhardware/include/hardware $(LOCAL_PATH)/../../../hardware/libhardware/include $(LOCAL_PATH)/src $(LOCAL_PATH)/../../RIP/inc
LOCAL_SHARED_LIBRARIES = libsmem.sastra
LOCAL_LDFLAGS := -v -L$(ANDROID_PRODUCT_OUT)/system/lib -lsmem.$(TARGET_BOARD_PLATFORM) -L$(LOCAL_PATH)/../../RIP/library -llibrary -llog -lcutils -lipc.$(TARGET_BOARD_PLATFORM)
#this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)
Take the .o of this file from out folder.
Get all .os from the library.
now
ar -x library.a //get original object files
pack all .os in this library with depend.o by this command
ar r library.a *.o //put depend.o with other object files
Now build the shared library
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libRip
LOCAL_SRC_FILES := src/Rip_api.cpp src/Rip_crypto.cpp
LOCAL_CFLAGS := -DCLR_INTERAPTIV_I7 -DCLR_INTERAPTIV -v
#only include corelockr and rip headers
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/ $(LOCAL_PATH)/include/ $(LOCAL_PATH)/../../hardware/libhardware/include/hardware/
LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/library -llibrary
LOCAL_SHARED_LIBRARIES = libsmem.sastra
#test seqr library
#LOCAL_LDFLAGS := -v -L$(LOCAL_PATH)/library -llibrary
#this option will build static library
include $(BUILD_SHARED_LIBRARY)
Now shared library should build without any issues.
*******Its a workaround, not a real solution.*******
I'm trying to add to the output executable filename of a autotool project the version number.
With libs is very simple: you can add -version-info option to Makefile.am
How can I do the same thing with bin_PROGRAMS
So far I tried:
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_${HELLO_VERSION_CURRENT}_${HELLO_VERSION_REVISION}_${HELLO_VERSION_AGE}
hello_SOURCES = hello.c
In this way it doesn't compile because of SOURCES must be: hello_1_2_1_SOURCES, but I don't know how to tell to automake that.
Another way could be to run a post-build script: how can I add post-build action to Makefile.am?
How about using some preset autoconf output variables in your Makefile.am:
bin_PROGRAMS = hello_#PACKAGE_VERSION#
hello_#PACKAGE_VERSION#_SOURCES = hello.c
The preceding works for me on Darwin with autoconf v2.69 and automake v1.15.
Using the PACKAGE_VERSION from within your source code is even easier: #include "config.h", that's where all the autoconf output variables are #defined. E.g.:
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
...
#define PACKAGE_VERSION "1.2.3-rc-whatever"
Reference:
https://www.gnu.org/software/autoconf/manual/autoconf#Output-Variable-Index
You can do it like this:
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)
hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)_SOURCES = hello.c
Although, in that case, I'd suggest making shorter variable names...
At the end I add the following to my Makefile.am
all:
cp ./.libs/hello ./.libs/hello_${HELLO_VERSION_CURRENT}_${HELLO_VERSION_REVISION}_${HELLO_VERSION_AGE}
EDIT
I found a new solution
HELLO_VERSION_CURRENT = 1
HELLO_VERSION_REVISION = 2
HELLO_VERSION_AGE = 1
bin_PROGRAMS = hello_$(HELLO_VERSION_CURRENT)_$(HELLO_VERSION_REVISION)_$(HELLO_VERSION_AGE)
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__SOURCES = hello.c
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__CFLAGS =
hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__LDFLAGS =
AM_CFLAGS = #hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__CFLAGS#
AM_LDFLAGS = #hello___HELLO_VERSION_CURRENT____HELLO_VERSION_REVISION____HELLO_VERSION_AGE__LDFLAGS#
CLEANFILES = *~
I am currently experiencing a really strange bug when compiling for u-boot:
The vector
init_fnc_t *init_sequence[] ={...}
is filled with 0's / NULLs instead of function pointers. I thought I outsmarted the compiler by calling all those functions 'by hand'. However this bug has even more ramifications as the driver struct also gets 0 / NULL pointers:
static struct serial_device my_serial_drv = {
.name = "my_serial",
.start = my_serial_init,
.stop = NULL,
.setbrg = my_serial_setbrg,
.putc = my_serial_putc,
.puts = my_serial_puts,
.getc = my_serial_getc,
.tstc = my_serial_tstc,
};
which, of course, when I call
'my_serial_drv'->start();
sets the pc to 0 and subsequently crashes everything.
Fun fact: the .name reaches the binary, so the .data sections are probably fine once they are set.
I have tested this with aarch64-linux-gnu-*-4.7 and aarch64-linux-gnu-*-4.9 binaries.
You can find 4.9 from:
http://releases.linaro.org/latest/components/toolchain/binaries.
Any help would be greatly appreciated :)
The u-boot.bin file seems allright. After investigating why this works I saw that u-boot's make is running a separate command to fix the bin:
start=$(aarch64-linux-gnu-nm u-boot | grep __rel_dyn_start | cut -f 1 -d ' ');
end=$(aarch64-linux-gnu-nm u-boot | grep __rel_dyn_end | cut -f 1 -d ' ');
tools/relocate-rela u-boot.bin 0x3e900000 $start $end
(these were a single line but I split it for readability )