I have installed GNAT 2018 (64 bits) on a PC Windows 8.1.
GNATColl seems well present and compiled through repertories :
C:/GNAT/2018/include/gnatcoll
C:/GNAT/2018/lib/gnatcoll.static
I try to compile this small test program :
with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.Terminal; use GNATCOLL.Terminal;
procedure Test_Colors is
Info : Terminal_Info;
begin
Info.Init_For_Stdout (Auto);
Info.Set_Color (Standard_Output, Blue, Yellow);
Put_Line ("A blue on yellow line");
Info.Set_Color (Standard_Output, Style => Reset_All);
Put_Line ("Back to standard colors -- much better");
end Test_Colors;
with the command :
gnatmake -gnat12 -gnatf -O3 "Test_Colors.adb" -aIC:/GNAT/2018/include/gnatcoll -aLC:/GNAT/2018/lib/gnatcoll.static
The file Test_Colors.ali is well created but then the binding goes wrong :
gnatbind -aIC:/GNAT/2018/include/gnatcoll -aOC:/GNAT/2018/lib/gnatcoll.static -x test_colors.ali
gnatlink test_colors.ali -O3
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x46d): undefined reference to `gnatcoll_get_console_screen_buffer_info'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x4f6): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x6c6): undefined reference to `gnatcoll_get_console_screen_buffer_info'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x729): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x73d): undefined reference to `gnatcoll_terminal_has_colors'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x9f3): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0xc93): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0xfb4): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x1372): undefined reference to `gnatcoll_set_console_text_attribute'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x23e): undefined reference to `gnatcoll_beginning_of_line'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x28e): undefined reference to `gnatcoll_clear_to_end_of_line'
.\gnatcoll-terminal.o:gnatcoll-terminal.adb:(.text+0x2d8): undefined reference to `gnatcoll_terminal_width'
collect2.exe: error: ld returned 1 exit status
gnatlink: error when calling C:\GNAT\2018\bin\gcc.exe
gnatmake: *** link failed.
Compilation échouée.
Do you know what to do to use successfully GNATColl ?
Jacob’s project file will indeed build (assuming you have your source in a subdirectory \src and are happy with having your executable in \bin), but this one is a lot simpler:
with "gnatcoll";
project Test_Colors is
for Main use ("test_colors.adb");
end Test_Colors;
The other options he shows will be extremely useful as you develop more advanced projects.
Use a project file and gprbuild. Something along these lines:
with "gnatcoll";
project Colors is
for Languages use ("Ada");
for Main use ("test_colors.adb");
for Source_Dirs use ("src/");
for Object_Dir use "obj/";
for Exec_Dir use "bin/";
package Builder is
for Default_Switches ("Ada")
use ("-m",
"-s");
end Builder;
package Compiler is
for Default_Switches ("Ada")
use ("-fstack-check", -- Generate stack checking code (part of Ada)
"-gnata", -- Enable assertions (part of Ada)
"-gnato13", -- Overflow checking (part of Ada)
"-gnatf", -- Full, verbose error messages
"-gnatwa", -- All optional warnings
"-gnatVa", -- All validity checks
"-gnaty3aAbcdefhiklnOprstux", -- Style checks
"-gnatyM125", -- Style checks
"-gnatwe", -- Treat warnings as errors
"-gnat2012", -- Use Ada 2012
"-Wall", -- All GCC warnings
"-O2"); -- Optimise (level 2/3)
end Compiler;
end Colors;
Now you can build your program with the command:
gprbuild -j0 -p -P colors.gpr
If you don't have any other project files in the directory you run the command from, it is even simpler:
gprbuild -j0 -p
Related
What command do I have to give to gnattest to make it only consider the code in my src directory (and ignore all subprojects such as the Ada Drivers Library)?
I've read this question, which says to tag every subprogram I want to test with the 'Test_Case' aspect. I'll go that route if I have to but I'd like the protection of gnattest automatically adding new test cases for new code so that I don't miss anything.
Here's my gpr file:
with "c:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\microbit_zfp.gpr";
project Demo_Project is
for Runtime ("ada") use Microbit_Zfp'Runtime ("Ada");
for Target use "arm-eabi";
for Main use ("main.adb");
for Languages use ("Ada");
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Create_Missing_Dirs use "True";
package Compiler renames Microbit_Zfp.Compiler;
package Linker is
for Default_Switches ("ada") use Microbit_Zfp.Linker_Switches & ("-Wl,--print-memory-usage", "-Wl,--gc-sections", "-U__gnat_irq_trap");
end Linker;
package Ide is
for Program_Host use ":1234";
for Communication_Protocol use "remote";
for Connection_Tool use "pyocd";
end Ide;
package Prove is
for Proof_Switches ("Ada") use ("-j0");
end Prove;
package Builder is
for Switches ("ada") use ("-j0", "-s");
end Builder;
end Demo_Project;
Here's the gnattest command that GPS created (which incorrectly created tests for the ada drivers library):
arm-eabi-gnat test -Pdemo_project.gpr --tests-dir=C:\Domains\ada\demo_project\microbit\tests
Update: 2019-12-17:
Here's what I got when I ran the suggested answer:
>c:\GNAT\2019\bin\gnattest -Pdemo_project.gpr --tests-dir=tests
Could not locate exec arm-eabi-gnatls
gprconfig: can't find a toolchain for the following configuration:
gprconfig: language 'ada', target 'arm-eabi', runtime 'zfp-cortex-m0'
microbit_zfp.gpr:61:25: warning: libraries are not supported on this platform
object path not found for runtime zfp-cortex-m0
gnattest: initialization failed
Update: 2019-12-17 (2):
I made some progress by adding the "--test-case-only" flag like so and adding a test_case aspect to a single procedure in the Battery package. Here's the command I ran:
arm-eabi-gnat test -dd -PC:\Domains\ada\Demo_Project\microbit\demo_project.gpr --tests-dir=C:\Domains\ada\Demo_Project\tests --test-case-only
Gnattest was successful. I can see my Battery package in the project view for the tests. However, when I try to build and run it from GPS, I get this mess:
gprbuild --target=arm-eabi -d -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr -XADL_BUILD_CHECKS=Enabled -XADL_BUILD=Debug -XTEST_DRIVER_BUILD_MODE=no-config-file C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_runner.adb -largs -Wl,-Map=map.txt
Compile
[Ada] test_runner.adb
[Ada] gnattest_main_suite.adb
[Ada] battery-test_data.adb
[Ada] battery-test_data-tests.adb
battery-test_data-tests.adb:40:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:40:13: warning: this handler can never be entered, and has been removed
battery-test_data-tests.adb:53:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:53:13: warning: this handler can never be entered, and has been removed
[Ada] battery-test_data-tests-suite.adb
[Ada] gnattest_generated.ads
Bind
[gprbind] test_runner.bexch
[Ada] test_runner.ali
Link
[link] test_runner.adb
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a(crt0.o): in function `hang':
(.text+0x40): undefined reference to `__stack_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x48): undefined reference to `__data_words'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x4c): undefined reference to `__data_load'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x54): undefined reference to `__bss_words'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a(crt0.o): in function `__vectors':
(.vectors+0x0): undefined reference to `__stack_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a(s-memory.o): in function `__gnat_malloc':
s-memory.adb:(.text.__gnat_malloc+0x40): undefined reference to `__heap_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a(s-memory.o):(.data.system__memory__top+0x0): undefined reference to `__heap_start'
collect2.exe: error: ld returned 1 exit status
gprbuild: link of test_runner.adb failed
gprbuild: failed command was: c:\gnat\2019-arm-elf\bin\arm-eabi-gcc.exe test_runner.o b__test_runner.o C:\Domains\ada\Demo_Project\microbit\obj\battery.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\gnattest_generated.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data-tests.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data-tests-suite.o C:\Domains\
ada\Demo_Project\microbit\obj\gnattest\harness\gnattest_main_suite.o C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a C:\gnat\2019-arm-elf\arm-eabi\zfp-cortex-m0\lib\aunit\libaunit.a -g -Wl,-Map=map.txt -LC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\ -LC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\ -LC:\gnat\2019-arm-elf\arm-eabi\zfp-cortex-m0\lib\aunit\ -LC:\Domains\ada\Demo_Project\microbit\obj\ -LC:\Domains\ada\Ada_Drive
rs_Library\boards\MicroBit\obj\zfp_lib_Debug\ -LC:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\ -static-libgcc C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a -Wl,-LC:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\/adalib -nostartfiles -nolibc -mlittle-endian -mthumb -msoft-float -mcpu=cortex-m0 -o test_runner
[2019-12-17 10:47:38] process exited with status 4, 100% (174/174), elapsed time: 03.00s
Traceback (most recent call last):
File "C:\GNAT\2019\share\gps\support\ui\workflows\__init__.py", line 351, in internal_run_as_wf
r = workflow(*args, **kwargs)
File "C:\GNAT\2019\share\gps\plug-ins\memory_usage_providers\ld.py", line 242, in async_fetch_memory_usage_data
visitor.on_memory_usage_data_fetched(regions, sections, modules)
GPS.Unexpected_Exception: unexpected internal exception raised CONSTRAINT_ERROR : Memory_Usage_Views.Memory_Region_Description_Maps.Reference: key not in map
[C:\GNAT\2019\bin\gps.exe]
0x21a541b
0x197c5b5
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7d79bc at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7d8b16 at ???
[C:\GNAT\2019\bin\gps.python27\python27.dll]
0x1e0c3d54
0x1e113eb9
0x1e114778
0x1e117ee2
0x1e119780
0x1e0b5831
0x1e08dae3
0x1e1141cb
0x1e117fbd
0x1e119780
0x1e0b5831
0x1e08dae3
0x1e09bfcf
0x1e08dae3
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e459f at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e55e0 at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e5833 at ???
[C:\GNAT\2019\bin\gps.libgnatcoll\libgnatcoll.dll]
0xc08dbb4 at ???
[C:\GNAT\2019\bin\gps.exe]
0x197ecf7
0x1975d5f
0x10687c2
0x14ba66a
0x145cc61
0x15e0780
0xfcfa72
0x10b4114
0x10b4672
0x10b7893
0x10b7cf7
0xe30b4c
0xe31022
0xe2deaa
[C:\GNAT\2019\bin\gps.libglib-2.0-0\libglib-2.0-0.dll]
g_timeout_dispatch at gmain.c:4545
g_main_context_dispatch at gmain.c:3122
g_main_context_iterate.isra.10 at gmain.c:3808
g_main_context_iteration at gmain.c:3869
[C:\GNAT\2019\bin\gps.libgio-2.0-0\libgio-2.0-0.dll]
g_application_run at gapplication.c:2308
[C:\GNAT\2019\bin\gps.exe]
0x425199
0x2150c58
0x4013f6
0x4014e9
[C:\windows\system32\kernel32.dll]
0x7768556b
[C:\windows\SYSTEM32\ntdll.dll]
0x777e372b
Build error. [workflow stopped]
There are three problems:
the autogenerated test code wants to throw exceptions but my project doesn't allow them.
I don't understand any of the output after that.
And I don't really understand how the gpr files work. I'm sure there's a magic incantation I can type there and get this sorted out but I've been googling and trying things for a whole day and I'm stuck.
FYI: I'm running the 2019 community versions of gnat, the ARM cross-compiler, and GPS on windows 7.
Update: 2019-12-18:
I've made some progress but it's still not working correctly. I edited the test_driver.gpr as Fabien suggested. I had to comment out the original linker package because it wouldn't work with two of them in the file.
test_driver.gpr now looks like this:
with "test_demo_project.gpr";
with "gnattest_common.gpr";
with "c:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\microbit_zfp.gpr";
project Test_Driver is
for Origin_Project use "..\..\..\demo_project.gpr";
for Target use Gnattest_Common'Target;
for Runtime ("Ada") use Gnattest_Common'Runtime ("Ada");
for Languages use ("Ada", "ASM_CPP");
for Main use ("test_runner.adb");
for Exec_Dir use ".";
package Builder renames Gnattest_Common.Builder;
-- package Linker renames Gnattest_Common.Linker;
package Linker is
for Default_Switches ("Ada") use MicroBit_ZFP.Linker_Switches &
("-Wl,--print-memory-usage",
"-Wl,--gc-sections");
end Linker;
package Binder renames Gnattest_Common.Binder;
package Compiler renames Gnattest_Common.Compiler;
package Ide renames test_demo_project.Ide;
package GNATtest is
for GNATTest_Mapping_File use "gnattest.xml";
end GNATtest;
end Test_Driver;
It doesn't fix the problem with test cases being generated for the ada drivers library but I can live with running gnattest with the "--test-case-only" flag, which largely accomplishes my goal.
But when I build the project it complains about the "ASM_CPP" language and the use of assertions. See below:
gprbuild --target=arm-eabi -d -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr -XADL_BUILD_CHECKS=Enabled -XADL_BUILD=Debug -XTEST_DRIVER_BUILD_MODE=no-config-file -largs -Wl,-Map=map.txt
test_driver.gpr:5:09: warning: there are no sources of language "ASM_CPP" in this project
Compile
[Ada] battery-test_data-tests.adb
battery-test_data-tests.adb:40:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:40:13: warning: this handler can never be entered, and has been removed
battery-test_data-tests.adb:53:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:53:13: warning: this handler can never be entered, and has been removed
Bind
[gprbind] test_runner.bexch
[Ada] test_runner.ali
Link
[link] test_runner.adb
Memory region Used Size Region Size %age Used
flash: 21668 B 256 KB 8.27%
ram: 3056 B 16 KB 18.65%
[2019-12-19 08:39:18] process terminated successfully, elapsed time: 02.08s
[2019-12-19 08:39:21] The selected rows in the Locations view cannot be exported, please select files and/or categories.
I tried removing the "ASM_CPP" text and the warning goes away. I don't know now to remove the warnings about the use of exceptions.
When I run my tests I get this:
arm-eabi-gnatemu -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_runner
[2019-12-19 08:40:01] process terminated successfully, elapsed time: 00.66s
I get the same output when I make my tests fail or pass. Is the warning about the use of exceptions causing the compiler to remove them, which breaks the tests? What do I have to do allow exceptions in my tests?
The question you linked is about testing only a few subprograms, not all the sources in one project, which should be as easy as:
gnattest -Pproject.gpr
You can specify one or more specific files:
gnattest -Pproject.gpr file1.ads file2.ads
Just avoid -r, and you should be fine:
-r Consider recursively all sources from all projects
The compilation errors in your last update seems to show that you did not specify the linker script and startup code.
Those are provided in Ada Drivers Library in the project file boards/MicroBit/microbit_zfp.gpr.
So you first have to "with" this project from the test_driver.gpr project, and then add those lines to the test_driver.gpr project:
package Linker is
for Default_Switches ("Ada") use MicroBit_ZFP.Linker_Switches &
("-Wl,--print-memory-usage",
"-Wl,--gc-sections");
end Linker;
You also have to add assembly in the list of languages in test_driver.gpr:
for Languages use ("Ada", "ASM_CPP");
I used
readelf --dyn-sym my_elf_binary | grep FUNC | grep UND
to display the dynamically imported functions of my_elf_binary, from the dynamic symbol table in the .dynsym section to be precise. Example output would be:
[...]
3: 00000000 0 FUNC GLOBAL DEFAULT UND tcsetattr#GLIBC_2.0 (3)
4: 00000000 0 FUNC GLOBAL DEFAULT UND fileno#GLIBC_2.0 (3)
5: 00000000 0 FUNC GLOBAL DEFAULT UND isatty#GLIBC_2.0 (3)
6: 00000000 0 FUNC GLOBAL DEFAULT UND access#GLIBC_2.0 (3)
7: 00000000 0 FUNC GLOBAL DEFAULT UND open64#GLIBC_2.2 (4)
[...]
Is it safe to assume that the names associated to these symbols, e.g. the tcsetattr or access, are always unique? Or is it possible, or reasonable*), to have a dynamic symbol table (filtered for FUNC and UND) which contains two entries with the same associated string?
The reason I am asking is that I am looking for a unique identifier for dynamically imported functions ...
*) Wouldn't the dynamic linker resolve all "UND FUNC symbols" with the same name to the same function anyway?
Yes, given a symbol name and the set of libraries an executable is linked against, you can uniquely identify the function. This behavior is required for linking and dynamic linking to work.
An illustrative example
Consider the following two files:
librarytest1.c:
#include <stdio.h>
int testfunction(void)
{
printf("version 1");
return 0;
}
and librarytest2.c:
#include <stdio.h>
int testfunction(void)
{
printf("version 2");
return 0;
}
Both compiled into shared libraries:
% gcc -fPIC -shared -Wl,-soname,liblibrarytest.so.1 -o liblibrarytest.so.1.0.0 librarytest1.c -lc
% gcc -fPIC -shared -Wl,-soname,liblibrarytest.so.2 -o liblibrarytest.so.2.0.0 librarytest2.c -lc
Note that we cannot put both functions by the same name into a single shared library:
% gcc -fPIC -shared -Wl,-soname,liblibrarytest.so.0 -o liblibrarytest.so.0.0.0 librarytest1.c librarytest2.c -lc
/tmp/cctbsBxm.o: In function `testfunction':
librarytest2.c:(.text+0x0): multiple definition of `testfunction'
/tmp/ccQoaDxD.o:librarytest1.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
This shows that symbol names are unique within a shared library, but do not have to be among a set of shared libraries.
% readelf --dyn-syms liblibrarytest.so.1.0.0 | grep testfunction
12: 00000000000006d0 28 FUNC GLOBAL DEFAULT 10 testfunction
% readelf --dyn-syms liblibrarytest.so.2.0.0 | grep testfunction
12: 00000000000006d0 28 FUNC GLOBAL DEFAULT 10 testfunction
Now lets link our shared libraries with an executable. Consider linktest.c:
int testfunction(void);
int main()
{
testfunction();
return 0;
}
We can compile and link this against either shared library:
% gcc -o linktest1 liblibrarytest.so.1.0.0 linktest.c
% gcc -o linktest2 liblibrarytest.so.2.0.0 linktest.c
And run each of them (note I'm setting the dynamic library path so the dynamic linker can find the libraries, which are not in a standard library path):
% LD_LIBRARY_PATH=. ./linktest1
version 1%
% LD_LIBRARY_PATH=. ./linktest2
version 2%
Now lets link our executable to both libraries. Each is exporting the same symbol testfunction and each library has a different implementation of that function.
% gcc -o linktest0-1 liblibrarytest.so.1.0.0 liblibrarytest.so.2.0.0 linktest.c
% gcc -o linktest0-2 liblibrarytest.so.2.0.0 liblibrarytest.so.1.0.0 linktest.c
The only difference is the order the libraries are referenced to the compiler.
% LD_LIBRARY_PATH=. ./linktest0-1
version 1%
% LD_LIBRARY_PATH=. ./linktest0-2
version 2%
Here are the corresponding ldd output:
% LD_LIBRARY_PATH=. ldd ./linktest0-1
linux-vdso.so.1 (0x00007ffe193de000)
liblibrarytest.so.1 => ./liblibrarytest.so.1 (0x00002b8bc4b0c000)
liblibrarytest.so.2 => ./liblibrarytest.so.2 (0x00002b8bc4d0e000)
libc.so.6 => /lib64/libc.so.6 (0x00002b8bc4f10000)
/lib64/ld-linux-x86-64.so.2 (0x00002b8bc48e8000)
% LD_LIBRARY_PATH=. ldd ./linktest0-2
linux-vdso.so.1 (0x00007ffc65df0000)
liblibrarytest.so.2 => ./liblibrarytest.so.2 (0x00002b46055c8000)
liblibrarytest.so.1 => ./liblibrarytest.so.1 (0x00002b46057ca000)
libc.so.6 => /lib64/libc.so.6 (0x00002b46059cc000)
/lib64/ld-linux-x86-64.so.2 (0x00002b46053a4000)
Here we can see that while symbols are not unique, the way the linker resolves them is defined (it appears that it always resolves the first symbol it encounters). Note that this is a bit of a pathological case as you normally wouldn't do this. In the cases where you would go this direction there are better ways of handling symbol naming so they would be unique when exported (symbol versioning, etc)
In summary, yes, you can uniquely identify the function given its name. If there happens to be multiple symbols by that name, you identify the proper one using the order the libraries are resolved in (from ldd or objdump, etc). Yes, in this case you need a bit more information that just its name, but it is possible if you have the executable to inspect.
Note that in your case, the name of the first function import is not just tcsetattr but tcsetattr#GLIBC_2.0. The # is how the readelf program displays a versioned symbol import.
GLIBC_2.0 is a version tag that glibc uses to stay binary compatible with old binaries in the (unusual but possible) case that the binary interface to one of its functions needs to change. The original .o file produced by the compiler will just import tcsetattr with no version information but during static linking, the linker has noticed that the actual symbol exported by lic.so carries a GLIBC_2.0 tag, and so it creates a binary that insists on importing the particular tcsetattr symbol that has version GLIBC_2.0.
In the future there might be a libc.so that exports one tcsetattr#GLIBC_2.0 and a different tcsetattr#GLIBC_2.42, and the version tag will then be used to find which one a partcular ELF object refers to.
It is possible that the same process may also use tcsetattr#GLIBC_2.42 at the same time, such as if it uses another dynamic library which was linked against a libc.so new enough to provide it. The version tags ensure that both the old binary and the new library get the function they expect from the C library.
Most libraries don't use this mechanism and instead just rename the entire library if they need to make breaking changes to their binary interfaces. For example, if you dump /usr/bin/pngtopnm you'll find that the symbols it imports from libnetpbm and libpng are not versioned. (Or at least that's what I see on my machine).
The cost of this is that you can't have a binary that links against one version of libpng and also links against another library that itself links against a different libpng version; the exported names from the two libpng's would clash.
In most cases this is manageable enough through careful packaging practice that maintaining the library source to produce useful version tags and stay backwards compatible is not worth the trouble.
But in the particular case of the C library and a few other vital system libraries, changing the name of the library would be so extremely painful that it makes sense for the maintainers to jump through some hoops in order to ensure it will never need to happen again.
Although in most cases every symbol is unique, there are a handful of exceptions. My favorite is multiple identical symbol import used by PAM (pluggable authentication modules) and NSS (Name Service Switch). In both cases all modules written for either interface use a standard interface with standard names. A common and frequently used example is what happens when you call get host by name. The nss library will call the same function in multiple libraries to get an answer. A common configuration calles the same function in three libraries! I have seen the same function called in five different libraries from one function call, and that was not the limit just what was useful. There is special calls to the dynamic linker need to do this and I have not familiarised myself with the mechanics of doing this, but there is nothing special about the linking of the library module that is so loaded.
I got this error below and I can not find a solution. Does anybody know how
to fix this error?
rafael#ubuntu:~/avr/projeto$ clang -fsyntax-only -Os -I /usr/lib/avr/include -D__AVR_ATmega328P__ -DARDUINO=100 -Wno-ignored-attributes -Wno-attributes serial_tree.c
In file included from serial_tree.c:3:
In file included from /usr/lib/avr/include/util/delay.h:43:
/usr/lib/avr/include/util/delay_basic.h:108:5: error: invalid output
constraint
'=w' in asm
: "=w" (__count)
^
1 error generated.
util/delay.h is a Header from avr-libc, and the feature which you are using (some of the delay stuff) is using inline asm to implement it. avr-libc is written to be used with avr-gcc and uses features from avr-gcc like machine dependent constrains in inline asm. llvm does not recognize constraint "w", thus you have to use a different approach like using avr-gcc or porting that code to llvm.
avr-gcc also implements built-in function __builtin_avr_delay_cycles to implement wasting a specified number of clock cycles. If llvm is properly mimicking avr-gcc, then you can use that function as a starting point.
I want to build Interbase plugin for Qt using MinGW toolchain.
According to Qt documentation, I can do it only by MSVC, but I need MinGW... So, I wrote this .cmd file
set QTDIR=C:\Qt\4.8.0-minGW
set PATH=C:\Qt\4.8.0-minGW\bin
set PATH=%PATH%;C:\MinGW\bin
set QMAKESPEC=win32-g++
set INCLUDE=%INCLUDE%;c:\Program Files\Borland\InterBase\SDK\include
set LIB=%LIB%;c:\Program Files\Borland\InterBase\SDK\lib_ms
qmake -o Makefile ibase.pro
mingw32-make.exe
pause
and ran it from c:\Qt\4.8.0-minGW\src\plugins\sqldrivers\ibase\. Whole output is very long, but there's many similar lines, that's why I'll show only one of them and the final lines
tmp/obj/debug_shared/qsql_ibase.o: In function `ZN12QIBaseDriver24qHandleEventNo
tificationEPv':
C:\Qt\4.8.0-minGW\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase/qsql_i
base.cpp:1845: undefined reference to `isc_event_counts'
C:\Qt\4.8.0-minGW\src\plugins\sqldrivers\ibase/../../../sql/drivers/ibase/qsql_i
base.cpp:1864: undefined reference to `isc_que_events'
collect2: ld returned 1 exit status
mingw32-make.exe: *** [debug-all] Error 2
Could you tell me, how should I achive my target. Thank you.
P.S. I googled a lot and saw this quiestion - Compiling InterBase support in Qt - but there wasn't exact answer what to do...
I've done it !!!
The problem was in header file ibase.h from Interbase's SDK. There was following lines:
#if (defined(_MSC_VER) && defined(_WIN32)) || \
(defined(__BORLANDC__) && (defined(__WIN32__) || defined(__OS2__)))
...
#define ISC_EXPORT __stdcall
...
Macro ISC_EXPORT was not defined and all function's declarations was wrong. When I changed these lines in the following way:
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
...
#define ISC_EXPORT __stdcall
...
plugin was successfuly build
I've a problem with the classic math function linking of my bare metal program with blackfin tool chain linker. I tried many things but I cannot see why the libm.a does't provide the definitions for the function it use. Do I need to add an extra library? if yes which one?
I've put my linker verbose lign with linked libraries and the example linking error I got.
Thanks,
William
bfin-elf-ld -v -o test_ad1836_driver -T coreb_test_ad1836_driver.lds --just-symbol ../../icc_core/icc queue.o ezkit_561.o heap_2.o port.o tasks.o test_ad1836_driver.o list.o croutine.o user_isr.o bfin_isr.o app_c.o context_sl_asm.o cycle_count.o CFFT_Rad4_NS_NBRev.o fir_decima.o fir_decima_spl.o math_tools.o -Ttext 0x3c00000 -L /opt/uClinux/bfin-elf/bfin-elf/lib -lbffastfp -lbfdsp -lg -lc -lm -Map=test_ad1836_driver.map
argv[0] = 'bfin-elf-ld'
bindir = '/opt/uClinux/bfin-elf/bin/'
tooldir = '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/'
linker = '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/ld.real'
elf2flt = '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/elf2flt'
nm = '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/nm'
objdump = '/opt/uClinux/bfin-elf/bin/bfin-elf-objdump'
objcopy = '/opt/uClinux/bfin-elf/bin/bfin-elf-objcopy'
ldscriptpath = '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/../lib'
Invoking: '/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/ld.real' '-v' '-o' 'test_ad1836_driver' '-T' 'coreb_test_ad1836_driver.lds' '--just-symbol' '../../icc_core/icc' 'queue.o' 'ezkit_561.o' 'heap_2.o' 'port.o' 'tasks.o' 'test_ad1836_driver.o' 'list.o' 'croutine.o' 'user_isr.o' 'bfin_isr.o' 'app_c.o' 'context_sl_asm.o' 'cycle_count.o' 'CFFT_Rad4_NS_NBRev.o' 'fir_decima.o' 'fir_decima_spl.o' 'math_tools.o' '-Ttext' '0x3c00000' '-L' '/opt/uClinux/bfin-elf/bfin-elf/lib' '-lbffastfp' '-lbfdsp' '-lg' '-lc' '-lm' '-Map=test_ad1836_driver.map'
GNU ld version 2.17
/opt/uClinux/bfin-elf/bfin-elf/lib/libm.a(w_atan2.o): In function `atan2':
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/w_atan2.c:96: undefined reference to `__eqdf2'
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/w_atan2.c:96: relocation truncated to fit: R_BFIN_PCREL24 against undefined symbol `__eqdf2'
.....
/opt/uClinux/bfin-elf/bfin-elf/lib/libm.a(e_sqrt.o): In function `_ieee754_sqrt':
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/e_sqrt.c:110: undefined reference to `__muldf3'
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/e_sqrt.c:110: undefined reference to `__adddf3'
.....
/opt/uClinux/bfin-elf/bfin-elf/lib/libm.a(s_atan.o): In function `atan':
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/s_atan.c:169: undefined reference to `__muldf3'
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/s_atan.c:170: undefined reference to `__muldf3'
/usr/src/packages/BUILD/blackfin-toolchain-2010R1/gcc-4.3/newlib/libm/math/s_atan.c:172: undefined reference to `__muldf3'
Add -lgcc. You need the functions to compare, add and multiply C double type values, respectively, __eqdf2, __adddf3 and __muldf3.
Usually, I'd recommend using the compiler driver (gcc) instead of linking directly with ld, even for firmware/kernel type outputs, because the former will take care of the necessary startup files and compiler runtime libraries.
Hi I think I know the problem, blackfin is not really compatible with the maths std lib. It is why in the VDSP version the maths functions are re implemented. To solve my problem, I did convert the VDSP maths lib to gcc and it compile fine now.
Thanks
Actually I found a better answer,
blackfin does in fact support std math. I just had some library flag in the wrong order.
For the linker, use the following lib flag order and it should work:
/opt/uClinux/bfin-elf/bin/../bfin-elf/bin/ld.real' '-v' '-o' .... '-L' '/opt/uClinux/bfin-elf/lib/gcc/bfin-elf/4.3.5/' '-lgcc' '-L' '/opt/uClinux/bfin-elf/bfin-elf/lib' '-lbfdsp' '-lg' '-lm' '-lbffastfp' '-lc'