Difference between pages "r7.1.1:Building Guide (liblfds)" and "r7.1.1:Building Guide (libshared)"

From liblfds.org
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
{{DISPLAYTITLE:Building Guide (liblfds)}}
{{DISPLAYTITLE:Building Guide (libshared)}}
==Introducton==
==Introducton==
The ''liblfds'' library uses a porting abstraction layer to mask platform differences.  Building ''liblfds'' requires build files (makefile, etc) for your toolchain (GCC, gnumake, etc) and a port of the abstraction layer to your platform.
The ''libshared'' library is used by ''libtest'', ''libbenchmark'', ''test'' and ''benchmark''.  As such, it must be built for any of these other components to build.  It is not used by, or needed to build, ''liblfds711''.


A small number of popular toolchains are supported out-of-the-box, and all supported toolchains have a porting abtraction layer provided.
The ''libshared'' library uses a porting abstraction layer to mask platform differences.  Building ''libshared'' requires build files (makefile, etc) for your toolchain (GCC, gnumake, etc) and a port of the abstraction layer to your platform.
 
A small number of popular toolchains are supported out-of-the-box, along with porting abstraction layers which cover Windows (user-mode and kernel-mode) and Linux (user-mode).  A kernel-mode Linux port is present but one function is unimplemented, as there is no kernel-mode Linux function to wait for a thread to complete, and so the ''libshared'' abstraction for threading has to be rewritten, and it was decided not to delay the 7.1.1 release for this work to be done.


==Supported Toolchains==
==Supported Toolchains==
Line 10: Line 12:
* GCC and gnumake
* GCC and gnumake
* GCC, kbuild and gnumake (Linux kernel toolchain)
* GCC, kbuild and gnumake (Linux kernel toolchain)
* MSVC and gnumake (Windows user-mode toolchain - and, yup, gnumake, not nmake)
* MSVC and and gnumake (Windows user-mode toolchain - and, yup, gnumake, not nmake)
* WDK 7.1 (Windows XP/Vista/7 kernel toolchain)
* WDK 7.1 (Windows XP/Vista/7 kernel toolchain)


Line 18: Line 20:


==Directory Structure==
==Directory Structure==
  └───liblfds711                                                  : liblfds library
  └───test_and_benchmark
    ├───bin                                                     : output directory - the library file ends up here
    └───libshared                                    : libshared library
    ├───build                                                   : build configuration directory - contains one directory per platform
        ├───bin                                     : output directory - the library file ends up here
    │  ├───gcc_gnumake                                         : GCC and gnumake
        ├───build                                   : build configuration directory - contains one directory per platform
    │  ├───gcc_gnumake_kbuild                                   : GCC, gnumake, and kbuild
        │  ├───gcc_gnumake                         : GCC and gnumake
    │  ├───msvc_gnumake                                         : Microsoft Visual C (command line compiler) and gnumake
        │  ├───gcc_gnumake_kbuild                   : GCC, gnumake, and kbuild
    │  └───wdk_7.1                                             : WDK 7.1
        │  ├───msvc_gnumake                         : Microsoft Visual C (command line compiler) and gnumake
    ├───inc                                                     : the public header files
        │  └───wdk_7.1                             : WDK 7.1
    │  └───liblfds711
        ├───inc                                     : the public header files
    ├───obj                                                     : temporary directory for object files
        │  └───libshared
    └───src                                                     : the data structures
        ├───obj                                     : temporary directory for object files
        ├───lfds711_btree_addonly_unbalanced                    : btree (add-only, unbalanced)
        └───src                                     : the source files
        ├───lfds711_freelist                                    : freelist
            ├───libshared_ansi                      : implementations of standard library functions
        ├───lfds711_hash_addonly                                : hash (add-only)
            ├───libshared_memory                    : memory container, for handling user provided store
        ├───lfds711_list_addonly_singlylinked_ordered            : singly-linked list (add-only, singly-linked, ordered)
            ├───libshared_misc                      : misc functions
        ├───lfds711_list_addonly_singlylinked_unordered          : singly-linked list (add-only, singly-linked, unordered)
            └───libshared_porting_abstraction_layer : porting abstraction layer
        ├───lfds711_misc                                        : misc library functions
        ├───lfds711_prng                                        : PRNG library functions
        ├───lfds711_queue_bounded_singleproducer_singleconsumer : queue (bounded, single-producer, single-consumer)
        ├───lfds711_queue_bounded_manyproducer_manyconsumer      : queue (bounded, many-producer, many-consumer)
        ├───lfds711_unqueue_bounded_manyproducer_manyconsumer    : queue (unbounded, many-producer, many-consumer)
        ├───lfds711_ringbuffer                                  : ringbuffer
        └───lfds711_stack                                        : stack


==Building==
==Building==
Line 47: Line 42:
This directory contains one directory per supported toolchain, where each such directory contains the files necessary to build for that toolchain.  Detailed descriptions of how to build for each toolchain are given below, with one heading per toolchain.
This directory contains one directory per supported toolchain, where each such directory contains the files necessary to build for that toolchain.  Detailed descriptions of how to build for each toolchain are given below, with one heading per toolchain.


The resultant library file will be placed in the top level directory ''liblfds711/bin/'', with the root filename ''liblfds711.*'', where the suffix varies by build type (static or dynamic) and by operating system (''.a'', ''.lib'', etc).
The various other components (''test'', ''benchmark'', etc) in their build files know the location of the resultant library file, so it does not need to be installed.
 
The header files are in the top level directory ''inc''.  They are arranged a single master header file, ''liblfds711/inc/liblfds711.h'' together with a subdirectory, ''liblfds711/inc/liblfds711/'', which contains a set of header files, one per data structure, where these per-data structure header files are included by the master file.
 
To use the header files, include and only include the master header file, ''liblfds711/inc/liblfds711.h''.


On all platforms, you need to clean between changing build types (debug, release, static, dynamic, profiled, etc), as there is only one directory used to hold object files.
On all platforms, you need to clean between changing build types (debug, release, static, dynamic, profiled, etc), as there is only one directory used to hold object files.
Line 58: Line 49:


===GCC and gnumake===
===GCC and gnumake===
  └───liblfds711
  └───test_and_benchmark
     └───build
     └───libshared
        └───gcc_gnumake
        └───build
                Makefile
            └───gcc_gnumake
                    Makefile


To build, install GCC and gnumake, enter the build directory and type;
To build, install GCC and gnumake, enter the build directory and type;
Line 75: Line 67:
  ar_tsan      : archive (.a), thread sanitizer
  ar_tsan      : archive (.a), thread sanitizer
  ar_vanilla  : archive (.a), no specific-build arguments
  ar_vanilla  : archive (.a), no specific-build arguments
ar_install  : install to /usr/local/include/ and /usr/local/lib/
ar_uninstall : uninstall
   
   
  so_cov      : shared (.so), coverage
  so_cov      : shared (.so), coverage
Line 84: Line 74:
  so_tsan      : shared (.so), thread sanitizer
  so_tsan      : shared (.so), thread sanitizer
  so_vanilla  : shared (.so), no specific-build arguments
  so_vanilla  : shared (.so), no specific-build arguments
so_install  : install to /usr/local/include/ and /usr/local/lib/ (creates the necessary soft links for .so versioning)
so_uninstall : uninstall
   
   
  clean        : what you'd expect
  clean        : what you'd expect
Line 94: Line 82:


===GCC, gnumake and kbuild===
===GCC, gnumake and kbuild===
  └───liblfds711
  └───test_and_benchmark
     └───build
     └───libshared
        └───gcc_gnumake_kbuild
        └───build
                Kbuild
            └───gcc_gnumake_kbuild
                Makefile
                    Kbuild
                    Makefile
 
Remember, although the build files are present, the porting abstraction layer is not fully implemented.  '''This platform cannot currently build'''.


To build, install GCC, gnumake, kbuild (and the Linux kernel headers), enter the build directory and type;
To build, install GCC, gnumake, kbuild (and the Linux kernel headers), enter the build directory and type;
Line 119: Line 110:


===MSVC and gnumake===
===MSVC and gnumake===
  └───liblfds711
  └───test_and_benchmark
     └───build
     └───libshared
        └───msvc_and_gnumake
        └───build
                liblfds711.def
            └───msvc_and_gnumake
                makefile
                    libshared.def
                    makefile


To build, install an MSVC command line compiler, enter the build directory and type;
To build, install an MSVC command line compiler, enter the build directory and type;
Line 142: Line 134:


===WDK 7.1===
===WDK 7.1===
  └───liblfds711
  └───test_and_benchmark
     └───build
     └───libshared
        └───wdk_7.1
        └───build
                dirs
            └───wdk_7.1
                driver_entry_renamed_to_avoid_compiler_warning.c
                    dirs
                liblfds711.def
                    driver_entry_renamed_to_avoid_compiler_warning.c
                readme_before_win_kernel_build.txt
                    libshared.def
                runme_before_win_kernel_dynamic_lib_build.bat
                    readme_before_win_kernel_build.txt
                runme_before_win_kernel_static_lib_build.bat
                    runme_before_win_kernel_dynamic_lib_build.bat
                sources.dynamic
                    runme_before_win_kernel_static_lib_build.bat
                sources.static
                    sources.dynamic
                    sources.static


All processor types are supported (x86, IA64, x64).
All processor types are supported (x86, IA64, x64).
Line 160: Line 153:
To deal with these limitations, it is necessary for a Windows kernel build to run a batch file prior to building.  There are two batch files, one for static library builds and the other for dynamic library builds.  They are idempotent; you can run them as often as you like and switch between them as often as you want.  It's all fine.
To deal with these limitations, it is necessary for a Windows kernel build to run a batch file prior to building.  There are two batch files, one for static library builds and the other for dynamic library builds.  They are idempotent; you can run them as often as you like and switch between them as often as you want.  It's all fine.


Both batch files copy all the sources file into a single directory, ''liblfds711/build/wdk7.1/single_dir_for_windows_kernel/''.
Both batch files copy all the sources file into a single directory, ''libshared/build/wdk7.1/single_dir_for_windows_kernel/''.


The static library batch file will then copy ''liblfds711/sources.static'' into ''liblfds711/build/wdk7.1/single_dir_for_windows_kernel/'', which will cause a static library to be built.
The static library batch file will then copy ''libshared/sources.static'' into ''libshared/build/wdk7.1/single_dir_for_windows_kernel/'', which will cause a static library to be built.


The dynamic library batch file will then copy ''liblfds711/sources.dynamic'' into ''liblfds711/build/wdk7.1/single_dir_for_windows_kernel/'', which will cause a dynamic library to be built.  It will also copy ''driver_entry_renamed_to_avoid_compiler_warning.c'' to ''liblfds711/build/wdk7.1/single_dir_for_windows_kernel/driver_entry.c'' (note the renaming), since the linker requires the ''DriverEntry'' function to exist, even though it's not used.
The dynamic library batch file will then copy ''libshared/sources.dynamic'' into ''libshared/build/wdk7.1/single_dir_for_windows_kernel/'', which will cause a dynamic library to be built.  It will also copy ''driver_entry_renamed_to_avoid_compiler_warning.c'' to ''libshared/build/wdk7.1/single_dir_for_windows_kernel/driver_entry.c'' (note the renaming), since the linker requires the ''DriverEntry'' function to exist, even though it's not used.


To build, start a build command line as usual, indicating through the command line you select whether you are making a debug or release build.  Then run the appropriate liblfds batch file to select a static or dynamic library.  Then, finally, run ''build.exe'' in the ''liblfds711/build/wdk_7.1/'' directory, with whatever arguments you prefer.
To build, start a build command line as usual, indicating through the command line you select whether you are making a debug or release build.  Then run the appropriate liblfds batch file to select a static or dynamic library.  Then, finally, run ''build.exe'' in the ''libshared/build/wdk_7.1/'' directory, with whatever arguments you prefer.


Note that due to limitations in the build environment, object files appear in a subdirectory in ''liblfds711/build/wdk7.1/single_dir_for_windows_kernel/'', rather than in the usual ''liblfds711/obj/''.  The final binary output however still appears almost as usual, in ''liblfds711/bin/[processor]/'', where processor might be ''i386''.  (The usual is just ''liblfds711/bin/'', with no subdirectories).
Note that due to limitations in the build environment, object files appear in a subdirectory in ''libshared/build/wdk7.1/single_dir_for_windows_kernel/'', rather than in the usual ''libshared/obj/''.  The final binary output however still appears almost as usual, in ''libshared/bin/[processor]/'', where processor might be ''i386''.  (The usual is just ''libshared/bin/'', with no subdirectories).


Note that the ''sources'' file used to compile the library asserts the define ''KERNEL_MODE''.  This appears to be necessary, due to the lack of a compiler-provided macro to differentiate in the code between a user-mode or kernel-mode build.
Note that the ''sources'' file used to compile the library asserts the define ''KERNEL_MODE''.  This appears to be necessary, due to the lack of a compiler-provided macro to differentiate in the code between a user-mode or kernel-mode build.


==See Also==
==See Also==
* [[r7.1.1:Release_7.1.1_Documentation|Release 7.1.1 Documentation]]
* [[r7.1.1:Building Guide (benchmarking)|Building Guide (benchmarking)]]
* [[r7.1.1:Building Guide (testing)|Building Guide (testing)]]

Latest revision as of 20:16, 17 February 2017

Introducton

The libshared library is used by libtest, libbenchmark, test and benchmark. As such, it must be built for any of these other components to build. It is not used by, or needed to build, liblfds711.

The libshared library uses a porting abstraction layer to mask platform differences. Building libshared requires build files (makefile, etc) for your toolchain (GCC, gnumake, etc) and a port of the abstraction layer to your platform.

A small number of popular toolchains are supported out-of-the-box, along with porting abstraction layers which cover Windows (user-mode and kernel-mode) and Linux (user-mode). A kernel-mode Linux port is present but one function is unimplemented, as there is no kernel-mode Linux function to wait for a thread to complete, and so the libshared abstraction for threading has to be rewritten, and it was decided not to delay the 7.1.1 release for this work to be done.

Supported Toolchains

The supported toolchains are;

  • GCC and gnumake
  • GCC, kbuild and gnumake (Linux kernel toolchain)
  • MSVC and and gnumake (Windows user-mode toolchain - and, yup, gnumake, not nmake)
  • WDK 7.1 (Windows XP/Vista/7 kernel toolchain)

Note that in 7.1.1, Visual Studio solution files are not provided. This is because there are over liblfds and the benchmark and benchmark libraries and programmes (seven projects in all) in the end due to the multple build variants (debug, release, library, DLL, kernel library, kernel DLL, and repeated twice, once for VS2012 and once for VS2013) what comes to something like ten thousand settings, all of which have to be set using a mouse and a GUI, which is not only extraordinarily time-consuming and error-prone, but emotionally agonizing.

Mac support is not available due to lack of access to a Mac.

Directory Structure

└───test_and_benchmark
    └───libshared                                    : libshared library
        ├───bin                                      : output directory - the library file ends up here
        ├───build                                    : build configuration directory - contains one directory per platform
        │   ├───gcc_gnumake                          : GCC and gnumake
        │   ├───gcc_gnumake_kbuild                   : GCC, gnumake, and kbuild
        │   ├───msvc_gnumake                         : Microsoft Visual C (command line compiler) and gnumake
        │   └───wdk_7.1                              : WDK 7.1
        ├───inc                                      : the public header files
        │   └───libshared
        ├───obj                                      : temporary directory for object files
        └───src                                      : the source files
            ├───libshared_ansi                       : implementations of standard library functions
            ├───libshared_memory                     : memory container, for handling user provided store
            ├───libshared_misc                       : misc functions
            └───libshared_porting_abstraction_layer  : porting abstraction layer

Building

The library directory tree contains at its top level directory called build.

This directory contains one directory per supported toolchain, where each such directory contains the files necessary to build for that toolchain. Detailed descriptions of how to build for each toolchain are given below, with one heading per toolchain.

The various other components (test, benchmark, etc) in their build files know the location of the resultant library file, so it does not need to be installed.

On all platforms, you need to clean between changing build types (debug, release, static, dynamic, profiled, etc), as there is only one directory used to hold object files.

Per-Toolchain Build Instructions

GCC and gnumake

└───test_and_benchmark
    └───libshared
        └───build
            └───gcc_gnumake
                    Makefile

To build, install GCC and gnumake, enter the build directory and type;

make

The following targets are available;

ar_cov       : archive (.a), coverage
ar_dbg       : archive (.a), debug
ar_prof      : archive (.a), profiling
ar_rel       : archive (.a), release
ar_tsan      : archive (.a), thread sanitizer
ar_vanilla   : archive (.a), no specific-build arguments

so_cov       : shared (.so), coverage
so_dbg       : shared (.so), debug
so_prof      : shared (.so), profiling
so_rel       : shared (.so), release
so_tsan      : shared (.so), thread sanitizer
so_vanilla   : shared (.so), no specific-build arguments

clean        : what you'd expect

When switching from one target to another, clean must be made.

If building *_ar_tsan, libtsan must be installed. This is not necessary if building *_so_tsan.

GCC, gnumake and kbuild

└───test_and_benchmark
    └───libshared
        └───build
            └───gcc_gnumake_kbuild
                    Kbuild
                    Makefile

Remember, although the build files are present, the porting abstraction layer is not fully implemented. This platform cannot currently build.

To build, install GCC, gnumake, kbuild (and the Linux kernel headers), enter the build directory and type;

make

The makefile is complimentory (mint-flavoured :-) and simply issues the necessary kbuild command.

There are three targets;

 clean
 help
 modules

Note that modules is the default build (i.e. with no arguments).

I do not properly understand kbuild. I've read the documentation; I find for example examples which have switches in which are simply not present in the documentation, and in general I don't see how libraries are built to fit in with larger projects. The most I can say about this build is that it compiles without warnings or errors. I am pretty sure it's not something which can be used as it is in a kernel build or driver, but anyone who knows enough to be developing such a thing should be able to take what is here (since it compiles against the kernel) and easily fit it into their work.

Any feedback on making this build proper is greatly appreciated.

MSVC and gnumake

└───test_and_benchmark
    └───libshared
        └───build
            └───msvc_and_gnumake
                    libshared.def
                    makefile

To build, install an MSVC command line compiler, enter the build directory and type;

make

The following targets are available;

libdbg : archive (.lib), debug
librel : archive (.lib), release

dlldbg : shared (.dll), debug
dllrel : shared (.dll), release

clean  : what you'd expect

When switching from one target to another, clean must be made.

WDK 7.1

└───test_and_benchmark
    └───libshared
        └───build
            └───wdk_7.1
                    dirs
                    driver_entry_renamed_to_avoid_compiler_warning.c
                    libshared.def
                    readme_before_win_kernel_build.txt
                    runme_before_win_kernel_dynamic_lib_build.bat
                    runme_before_win_kernel_static_lib_build.bat
                    sources.dynamic
                    sources.static

All processor types are supported (x86, IA64, x64).

The WDK 7.1 kernel build environment is primitive and has a number of severe limitations; in particular, all source files must be in one directory and it is not possible to choose the output binary type (static or dynamic library) from the build command line; rather, a string has to be modified in a text file used by the build (!)

To deal with these limitations, it is necessary for a Windows kernel build to run a batch file prior to building. There are two batch files, one for static library builds and the other for dynamic library builds. They are idempotent; you can run them as often as you like and switch between them as often as you want. It's all fine.

Both batch files copy all the sources file into a single directory, libshared/build/wdk7.1/single_dir_for_windows_kernel/.

The static library batch file will then copy libshared/sources.static into libshared/build/wdk7.1/single_dir_for_windows_kernel/, which will cause a static library to be built.

The dynamic library batch file will then copy libshared/sources.dynamic into libshared/build/wdk7.1/single_dir_for_windows_kernel/, which will cause a dynamic library to be built. It will also copy driver_entry_renamed_to_avoid_compiler_warning.c to libshared/build/wdk7.1/single_dir_for_windows_kernel/driver_entry.c (note the renaming), since the linker requires the DriverEntry function to exist, even though it's not used.

To build, start a build command line as usual, indicating through the command line you select whether you are making a debug or release build. Then run the appropriate liblfds batch file to select a static or dynamic library. Then, finally, run build.exe in the libshared/build/wdk_7.1/ directory, with whatever arguments you prefer.

Note that due to limitations in the build environment, object files appear in a subdirectory in libshared/build/wdk7.1/single_dir_for_windows_kernel/, rather than in the usual libshared/obj/. The final binary output however still appears almost as usual, in libshared/bin/[processor]/, where processor might be i386. (The usual is just libshared/bin/, with no subdirectories).

Note that the sources file used to compile the library asserts the define KERNEL_MODE. This appears to be necessary, due to the lack of a compiler-provided macro to differentiate in the code between a user-mode or kernel-mode build.

See Also