purpose of .dynsym section in executable - dll

What is the purpose of .dynsym section in executable I see that it is allocable to strip won't remove it. So, how does dynamic linker loader interprets it?

Related

CMAKE Find file based on extension

How can I find a file inside a directory based on the file extension?
I want to create a function that finds a linker script. The function will be defined in the toolchain file, because each compiler has a different type of linker script.
I want to pass to the function a path to a directory with linker files for all type of supported compilers.
The function implemented for the specific compiler will find the right linker file (for example, armcc compiler will find the file with the extension .sct)
Thanks for the help.

CMake add linker options after .obj files

Cross compiling an executable for an embedded system with CMake requires me to manually add link options to link libc, libgcc and whatnot. However using target_link_options for that results in a linker call where all those additional link options are added in front of all the object files generated from my actual code. I believe that this is the wrong linking order and it causes "duplicate symbol errors" whenever I try to overwrite weak symbols from the standard library (e.g. __cxa_pure_virtual).
Here is an exemplar of the output I get from the linking stage
"/usr/bin/ld.lld"
--gc-sections
/usr/arm-none-eabi/lib/crt0.o
/usr/lib/gcc/arm-none-eabi/10.1.0/thumb/v7e-m+fp/hard/crti.o
/usr/lib/gcc/arm-none-eabi/10.1.0/thumb/v7e-m+fp/hard/crtbegin.o
/usr/lib/gcc/arm-none-eabi/10.1.0/thumb/v7e-m+fp/hard/crtn.o
/usr/lib/gcc/arm-none-eabi/10.1.0/thumb/v7e-m+fp/hard/crtend.o
--start-group -lstdc++_nano -lm -lgcc -lc_nano --end-group
my.obj ///< Shoudln't object files and application libs be linked first?
libmylib.a
-Bstatic
-L/usr/lib/clang/10.0.0/lib/baremetal
-L/usr/arm-none-eabi/lib/thumb/v7e-m+fp/hard/
-L/usr/lib/gcc/arm-none-eabi/10.1.0/thumb/v7e-m+fp/hard/
-T ldscript.ld
-o myelf
Is there any way to solve this in CMake?
target_link_options specifies options to the linker - and typically options are specified before anything else. Use target_link_libraries to link with libraries.

What is the default folder for cmake to search for libraries in Linux?

If I give some libraries in target_link_libraries (like GL, Glfw, glew), what is the default place, where cmake search for these libs?
For example:
target_link_libraries(aplication GL glfw GLEW)
Does Cmake search for these libs in the Path environment variable in Linux? Where can I find these libs?
From cmake target_link_libraries:
A plain library name: The generated link line will ask the linker to search for the library (e.g. foo becomes -lfoo or foo.lib).
Just to point you in the right direction as to what are the standard linker search paths, this post on unix.stackexchange explains it.

Autotools: setting 'influential environment variables'

When running './configure --help', at the end you get an output similar to this:
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CPP C preprocessor
CXXCPP C++ preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
lib_CFLAGS C compiler flags for <lib>, overriding pkg-config
lib_LIBS linker flags for <lib>, overriding pkg-config
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
How can I add custom variables in the list above? I know it's possible, PKG_CHECK_MODULES() does this. Looking at pkg.m4 (which defines PKG_CHECK_MODULES), I saw that the macro also sets pkg_cv_lib_CFLAGS and ac_cv_env_lib_CFLAGS.
I tried that with custom 'ac_cv_env_...' and 'pkg_cv_...' variables, but I had no luck. What can I do?
Thanks in advance
You can add "precious" variables by using AC_ARG_VAR.
AC_ARG_VAR([FOO],[FOO does something])

gcc vs. clang: symbol stripping

gcc and AMD Open64 opencc both have a -s option to "strip symbol table and relocation information". So far I haven't been able to find the same option in Clang/LLVM. Does it exist?
You can use a strip utility from binutils.
Actually, a llvm-ld has this options http://llvm.org/cmds/llvm-ld.html
-strip-all, -s Strip all debug and symbol information from the executable
to make it smaller.
-strip-debug, -S Strip all debug information from the executable to
make it smaller.
opt have something too:
-strip-debug
This option causes opt to strip debug information from the module before applying other
optimizations. It is essentially the same as -strip but it ensures that stripping of debug
information is done first.