How to generate assembly code (*.s) file from kernel module (*.c )? - gcc

I have written one kernel module, I want to generate assembly code i.e *.s file.
Till now I am able to generate .s file from object file by using objdump but it's not providing me proper assembly code. Can anyone please help me with this.

You have to use -S option for generating an assembly code, also I would suggest to disable any optimization with -O0 option (if you need it) , if you want to see optimized assmbly code, just add -S
More info about gcc options you may find here

Related

Link a static library to object in cmake

I am trying to compile a project using cmake. I need to use an external static library in src1.c so I utilized target_link_libraries to link it to the object file. However, I am getting some complains about missing functions in src1.c which should be in the external library.
add_library(input_output OBJECT
src/src1.c
src/src2.c
src/src3.c)
find_library(EXTERNAL_LIB NAMES libexternallib.a PATHS ~/lib)
target_link_libraries(input_output PRIVATE
"${EXTERNAL_LIB}")
So I am not sure what I should do at this point. the logic sounds right at least
UPDATE1: I also added the external library directly into the linker command
add_compile_options(-Wall -Wextra --std=c99 -L~/lib -lexternallib)
add_link_options(-L~/lib -lexternallib)
but this added the library flags before the object file for the linker command, which leads to some other problem with ordering the linker arguments
It's hard to say what is really the reason for your error here, but I'll give it a try.
First of all, you don't need to link manually with add_compile_options or add_link_options. The cmake command target_link_libraries is doing that for you.
What I could imagine, because of the missing functions, that you need to add a header include directory from the dependency.
e.g.:
target_include_directories(input_output PRIVATE /path/to/external_library_header)

cmake - preprocess entire project and store output in file

i have a huge arm-none-eabi (gcc) cmake project.
i would like to run the entire project and abort after the preprocessor.
so example:
if i have 500 headers and 600 source files, i would like to get 1100 additional files after the preprocessor, all in a preprocessed state.
eg
// my procject
main.cpp
src/dummy.cpp
src/etc.cpp
...
// my project after preprocessor
main.cpp
main_preprocessed.cpp
src/dummy.cpp
src/dummy_preprocessed.cpp
...
if i just add the compiler flag -E, the prepocessing happens and thells me 'linker input file unused because linking not done'. which is ok, but i dont get the preprocessed files.
just preprocessing one file is no good to me because i would need to add a lot of header files with -I, which takes a long time.
ADDITIONAL INFO:
also, what is important is that i need my project files preprocessed. additionally to my project files i do have some libraries from different manufacturers, those i build first into a static lib, then link against the lib.

Step to pass "-std=c++11" flag in gdb regression test-suite setup

I am trying to run GDB testsuite with "-std=c++11" flag for the subtest case under "gdb.cp" folder or for the CPP related test-cases.
Currently I am performing it using DejaGnu directive "dg-options" in CPP test-case like :
// { dg-options "-std=c++11" }
But I am not confirm whether this is right way or not. Because if I check the gdb.log file, I am not seeing "-std=c++11" flag passed at compile time.
The easiest way would be, from the top-level build directory, to run the tests like:
make check-gdb RUNTESTFLAGS="CXX_FOR_TARGET='g++ --std=c++11' gdb.cp/*.exp"
GDB also supports CFLAGS_FOR_TARGET which can be set in the same way, despite being called CFLAGS these flags are appended for any compile, so you'll start to see warnings/errors about --std=c++11 being an invalid option for C tests, etc.
A final option that might be of interest would be creating a whole new DeJaGNU board file which would override the compiler flags, however, I couldn't get this working so quickly, so your mileage may vary.
You can find more information about running the tests here: https://sourceware.org/gdb/wiki/TestingGDB

Scons: how to specify file dependency for 3rd party compile result?

It seem to me that scons targets are being generated not in declaration sequence. My problem is, I need to generate some code first, I'm using protoc to process a my.proto file into .h and .cc file, I need some pseudo code like this(what should the working code look like?)
import os
env=Environment(ENV=os.environ,LIBPATH='/usr/local/lib')
env.ShellExecute('protoc', '--outdir=. --out-lang=cpp', 'my.proto')//produces my.cc
myObj=Object('my.cc')//should wait until 'my.cc' is generated by protoc
Dependency(myObj, 'my.cc')
mainObj=Object('main.cpp')
My question is:
How to specify this ShellExecution of protoc in SConstruct/SConscript?
How to make sure that the compilation of 'main.cpp' depends on the existence of 'my.cc', in another word, wait until 'my.cc' is generated and then execute?
Your observations and assumptions are correct, SCons will not execute the single build commands in the order that you list them in the SConstruct files. It will run them based on the dependencies of the targets and source files in your build, either defined implicitly (header includes in C++, for example) or explicitly (via the Depends() method).
So you have to define and setup your dependencies correctly, such that SCons delivers the output that you want. For the special protoc case in your example, a special Builder exists that will help you to get the dependency graph right. It is available in our ToolsIndex, where also support for a variety of other languages and dialects can be found.
These special builders will emit the correct target nodes, e.g. when given a *.proto input file, and SCons is then able to automatically detect the dependency between the protoc input file and your main program if you say something like:
env=Environment(tools=['default','protoc'])
env.Protoc([], "test.proto")
env.Program('main', ['main.cpp'] + Glob('*.cc'))
The Glob('*.cc') will detect your *.cc files, coming out of the protoc Tool, and include them as dependencies for your final target main.
You can always write your own Builders and Emitters in SCons, which is the canonical way of making new tools/toolchains known to SCons dependency analysis. In the UserGuide, sect. "18 Writing Your Own Builders", and especially our ToolsForFools Guide you can find more infos about this.

Compiling Bzip2 with C++11

I'm trying to compile the MultiBoost Library with C++11 but I can't make it work. The problem seems to be with the BZip2 Library that is used internally. More specificly there is a wrapper called Bzip2Wrapper to provide a c++ interface to the C library. All the files of the C library are included in the same folder. When using the default make file everything works but when I change
project(multiboost)
to
project(multiboost CXX)
I get the following errors:
libMultiBoostLib.a(Serialization.cpp.o): In function `Bzip2WrapperReader::open(char const*)':
Serialization.cpp:(.text._ZN18Bzip2WrapperReader4openEPKc[_ZN18Bzip2WrapperReader4openEPKc]+0x97): undefined reference to `BZ2_bzReadOpen'
Serialization.cpp:(.text._ZN18Bzip2WrapperReader4openEPKc[_ZN18Bzip2WrapperReader4openEPKc]+0xc5): undefined reference to `BZ2_bzReadClose'
libMultiBoostLib.a(Serialization.cpp.o): In function `Bzip2WrapperReader::close()': ...
The CMakeList file looks like this
# Bzip2
file(GLOB bzip2_SRCS "${BASEPATH}/Bzip2/*.cpp" "${BASEPATH}/Bzip2/*.c" "${BASEPATH}/Bzip2/*.h")
add_library(Bzip2Lib STATIC ${bzip2_SRCS})
#add_library(bzip2 SHARED ${bzip2_lib_SRCS})
...
# adding library to the exec
target_link_libraries(multiboost MultiBoostLib Bzip2Lib)
Any ideas what could go wrong? I don't even know what the problem is.
Thanks!
This does not look like a C++11 error but an error in the Build system.
I have not looked at the Code, but from the output you added something like this
target_link_libraries(MultiBoostLib PUBLIC Bzip2Lib)
should add the missing dependency from libMultiBoostLib on libBzip2Lib.
I found the problem. I was adding "CXX" to my project description which disabled the use of C. Therefore the libraries (in C) could not be compiled. Changing it to "project(name C CXX)" solved this issue. I then also needed to include the line "set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")" to enable C++11 support. Now everything is working.
Thanks a lot!

Resources