mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 12:34:26 +01:00
userland: use path_properties flags for all builds, including lkmc. and userland/arch/main.c
Without this in particular, --gdb fails on assembly because main.c was not being built with -ggdb3.
This commit is contained in:
269
build-userland
269
build-userland
@@ -46,55 +46,127 @@ Default: build all examples that have their package dependencies met, e.g.:
|
|||||||
self,
|
self,
|
||||||
in_path,
|
in_path,
|
||||||
out_path,
|
out_path,
|
||||||
cc_flags,
|
build_exts=None,
|
||||||
|
cc_flags=None,
|
||||||
cc_flags_after=None,
|
cc_flags_after=None,
|
||||||
c_std=None,
|
extra_objs_userland_asm=None,
|
||||||
cxx_std=None,
|
extra_objs_lkmc_common=None,
|
||||||
extra_deps=None,
|
extra_deps=None,
|
||||||
extra_objs=None,
|
|
||||||
link=True,
|
link=True,
|
||||||
):
|
):
|
||||||
if extra_deps is None:
|
if cc_flags is None:
|
||||||
extra_deps = []
|
cc_flags = []
|
||||||
if extra_objs is None:
|
else:
|
||||||
extra_objs = []
|
cc_flags = cc_flags.copy()
|
||||||
if cc_flags_after is None:
|
if cc_flags_after is None:
|
||||||
cc_flags_after = []
|
cc_flags_after = []
|
||||||
|
else:
|
||||||
|
cc_flags_after = cc_flags_after.copy()
|
||||||
|
if extra_deps is None:
|
||||||
|
extra_deps = []
|
||||||
ret = 0
|
ret = 0
|
||||||
if self.need_rebuild([in_path] + extra_objs + extra_deps, out_path):
|
in_dir, in_basename = os.path.split(in_path)
|
||||||
cc_flags = cc_flags.copy()
|
in_dir_abs = os.path.abspath(in_dir)
|
||||||
if not link:
|
dirpath_relative_root = in_dir_abs[len(self.env['userland_source_dir']) + 1:]
|
||||||
cc_flags.extend(['-c', LF])
|
dirpath_relative_root_components = dirpath_relative_root.split(os.sep)
|
||||||
in_ext = os.path.splitext(in_path)[1]
|
dirpath_relative_root_components_len = len(dirpath_relative_root_components)
|
||||||
if in_ext in (self.env['c_ext'], self.env['asm_ext']):
|
my_path_properties = path_properties.get(os.path.join(
|
||||||
cc = self.env['gcc']
|
self.env['userland_subdir'],
|
||||||
if c_std is None:
|
dirpath_relative_root,
|
||||||
std = path_properties.PathProperties.default_c_std
|
in_basename
|
||||||
else:
|
))
|
||||||
std = c_std
|
if my_path_properties.should_be_built(self.env, link):
|
||||||
elif in_ext == self.env['cxx_ext']:
|
extra_objs= []
|
||||||
cc = self.env['gxx']
|
if my_path_properties['extra_objs_lkmc_common']:
|
||||||
if cxx_std is None:
|
extra_objs.extend(extra_objs_lkmc_common)
|
||||||
std = path_properties.PathProperties.default_cxx_std
|
if my_path_properties['extra_objs_userland_asm']:
|
||||||
else:
|
extra_objs.extend(extra_objs_userland_asm)
|
||||||
std = cxx_std
|
if self.need_rebuild([in_path] + extra_objs + extra_deps, out_path):
|
||||||
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
cc_flags.extend(my_path_properties['cc_flags'])
|
||||||
ret = self.sh.run_cmd(
|
cc_flags_after.extend(my_path_properties['cc_flags_after'])
|
||||||
(
|
if my_path_properties['cc_pedantic']:
|
||||||
[
|
cc_flags.extend(['-pedantic', LF])
|
||||||
cc, LF,
|
if not link:
|
||||||
] +
|
cc_flags.extend(['-c', LF])
|
||||||
cc_flags +
|
in_ext = os.path.splitext(in_path)[1]
|
||||||
[
|
if in_ext in (self.env['c_ext'], self.env['asm_ext']):
|
||||||
'-std={}'.format(std), LF,
|
cc = self.env['gcc']
|
||||||
'-o', out_path, LF,
|
std = my_path_properties['c_std']
|
||||||
in_path, LF,
|
elif in_ext == self.env['cxx_ext']:
|
||||||
] +
|
cc = self.env['gxx']
|
||||||
self.sh.add_newlines(extra_objs) +
|
std = my_path_properties['cxx_std']
|
||||||
cc_flags_after
|
if dirpath_relative_root_components_len > 0:
|
||||||
),
|
if dirpath_relative_root_components[0] == 'arch':
|
||||||
extra_paths=[self.env['ccache_dir']],
|
cc_flags.extend([
|
||||||
)
|
'-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF,
|
||||||
|
'-I', os.path.join(self.env['userland_source_arch_dir']), LF,
|
||||||
|
])
|
||||||
|
elif dirpath_relative_root_components[0] == 'libs':
|
||||||
|
if dirpath_relative_root_components_len > 1:
|
||||||
|
if self.env['gcc_which'] == 'host':
|
||||||
|
eigen_root = '/'
|
||||||
|
else:
|
||||||
|
eigen_root = self.env['buildroot_staging_dir']
|
||||||
|
packages = {
|
||||||
|
'eigen': {
|
||||||
|
# TODO: was failing with:
|
||||||
|
# fatal error: Eigen/Dense: No such file or directory as of
|
||||||
|
# 975ce0723ee3fa1fea1766e6683e2f3acb8558d6
|
||||||
|
# http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html
|
||||||
|
'cc_flags': [
|
||||||
|
'-I',
|
||||||
|
os.path.join(
|
||||||
|
eigen_root,
|
||||||
|
'usr',
|
||||||
|
'include',
|
||||||
|
'eigen3'
|
||||||
|
),
|
||||||
|
LF
|
||||||
|
],
|
||||||
|
# Header only.
|
||||||
|
'cc_flags_after': [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
package_key = dirpath_relative_root_components[1]
|
||||||
|
if package_key in packages:
|
||||||
|
package = packages[package_key]
|
||||||
|
else:
|
||||||
|
package = {}
|
||||||
|
if 'cc_flags' in package:
|
||||||
|
cc_flags.extend(package['cc_flags'])
|
||||||
|
else:
|
||||||
|
pkg_config_output = subprocess.check_output([
|
||||||
|
self.env['pkg_config'],
|
||||||
|
'--cflags',
|
||||||
|
package_key
|
||||||
|
]).decode()
|
||||||
|
cc_flags.extend(self.sh.shlex_split(pkg_config_output))
|
||||||
|
if 'cc_flags_after' in package:
|
||||||
|
cc_flags.extend(package['cc_flags_after'])
|
||||||
|
else:
|
||||||
|
pkg_config_output = subprocess.check_output([
|
||||||
|
self.env['pkg_config'],
|
||||||
|
'--libs',
|
||||||
|
package_key
|
||||||
|
]).decode()
|
||||||
|
cc_flags_after.extend(self.sh.shlex_split(pkg_config_output))
|
||||||
|
os.makedirs(os.path.dirname(out_path), exist_ok=True)
|
||||||
|
ret = self.sh.run_cmd(
|
||||||
|
(
|
||||||
|
[
|
||||||
|
cc, LF,
|
||||||
|
] +
|
||||||
|
cc_flags +
|
||||||
|
[
|
||||||
|
'-std={}'.format(std), LF,
|
||||||
|
'-o', out_path, LF,
|
||||||
|
in_path, LF,
|
||||||
|
] +
|
||||||
|
self.sh.add_newlines(extra_objs) +
|
||||||
|
cc_flags_after
|
||||||
|
),
|
||||||
|
extra_paths=[self.env['ccache_dir']],
|
||||||
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
@@ -105,61 +177,36 @@ Default: build all examples that have their package dependencies met, e.g.:
|
|||||||
] + self.sh.shlex_split(self.env['ccflags'])
|
] + self.sh.shlex_split(self.env['ccflags'])
|
||||||
if self.env['static']:
|
if self.env['static']:
|
||||||
cc_flags.extend(['-static', LF])
|
cc_flags.extend(['-static', LF])
|
||||||
common_obj = os.path.join(
|
extra_obj_lkmc_common = os.path.join(
|
||||||
build_dir,
|
build_dir,
|
||||||
self.env['common_basename_noext'] + self.env['obj_ext']
|
self.env['common_basename_noext'] + self.env['obj_ext']
|
||||||
)
|
)
|
||||||
self._build_one(
|
self._build_one(
|
||||||
in_path=self.env['common_c'],
|
in_path=self.env['common_c'],
|
||||||
out_path=common_obj,
|
out_path=extra_obj_lkmc_common,
|
||||||
cc_flags=cc_flags,
|
cc_flags=cc_flags,
|
||||||
extra_deps=[self.env['common_h']],
|
extra_deps=[self.env['common_h']],
|
||||||
link=False,
|
link=False,
|
||||||
)
|
)
|
||||||
common_obj_asm = os.path.join(
|
extra_obj_userland_asm = os.path.join(
|
||||||
build_dir,
|
build_dir,
|
||||||
'arch',
|
'arch',
|
||||||
'main' + self.env['obj_ext']
|
'main' + self.env['obj_ext']
|
||||||
)
|
)
|
||||||
common_obj_asm_relpath = os.path.join(
|
extra_obj_userland_asm_relpath = os.path.join(
|
||||||
'arch',
|
'arch',
|
||||||
'main' + self.env['c_ext']
|
'main' + self.env['c_ext']
|
||||||
)
|
)
|
||||||
self._build_one(
|
self._build_one(
|
||||||
in_path=os.path.join(
|
in_path=os.path.join(
|
||||||
self.env['userland_source_dir'],
|
self.env['userland_source_dir'],
|
||||||
common_obj_asm_relpath
|
extra_obj_userland_asm_relpath
|
||||||
),
|
),
|
||||||
out_path=common_obj_asm,
|
out_path=extra_obj_userland_asm,
|
||||||
cc_flags=cc_flags,
|
cc_flags=cc_flags,
|
||||||
extra_deps=[self.env['common_h']],
|
extra_deps=[self.env['common_h']],
|
||||||
link=False,
|
link=False,
|
||||||
)
|
)
|
||||||
if self.env['gcc_which'] == 'host':
|
|
||||||
eigen_root = '/'
|
|
||||||
else:
|
|
||||||
eigen_root = self.env['buildroot_staging_dir']
|
|
||||||
packages = {
|
|
||||||
'eigen': {
|
|
||||||
# TODO: was failing with:
|
|
||||||
# fatal error: Eigen/Dense: No such file or directory as of
|
|
||||||
# 975ce0723ee3fa1fea1766e6683e2f3acb8558d6
|
|
||||||
# http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html
|
|
||||||
'cc_flags': [
|
|
||||||
'-I',
|
|
||||||
os.path.join(
|
|
||||||
eigen_root,
|
|
||||||
'usr',
|
|
||||||
'include',
|
|
||||||
'eigen3'
|
|
||||||
),
|
|
||||||
LF
|
|
||||||
],
|
|
||||||
# Header only.
|
|
||||||
'cc_flags_after': [],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
rootdir_abs_len = len(self.env['userland_source_dir'])
|
|
||||||
with ThreadPool(
|
with ThreadPool(
|
||||||
self._build_one,
|
self._build_one,
|
||||||
nthreads=self.env['nproc'],
|
nthreads=self.env['nproc'],
|
||||||
@@ -167,76 +214,20 @@ Default: build all examples that have their package dependencies met, e.g.:
|
|||||||
try:
|
try:
|
||||||
for target in self.env['targets']:
|
for target in self.env['targets']:
|
||||||
for path, in_dirnames, in_filenames in self.sh.walk(target):
|
for path, in_dirnames, in_filenames in self.sh.walk(target):
|
||||||
path_abs = os.path.abspath(path)
|
|
||||||
dirpath_relative_root = path_abs[rootdir_abs_len + 1:]
|
|
||||||
dirpath_relative_root_components = dirpath_relative_root.split(os.sep)
|
|
||||||
dirpath_relative_root_components_len = len(dirpath_relative_root_components)
|
|
||||||
out_dir = os.path.join(
|
|
||||||
build_dir,
|
|
||||||
dirpath_relative_root
|
|
||||||
)
|
|
||||||
for in_filename in in_filenames:
|
for in_filename in in_filenames:
|
||||||
in_path = os.path.join(path, in_filename)
|
|
||||||
cc_flags_file = cc_flags.copy()
|
|
||||||
cc_flags_after = []
|
|
||||||
in_ext = os.path.splitext(in_filename)[1]
|
in_ext = os.path.splitext(in_filename)[1]
|
||||||
if not in_ext in self.env['userland_in_exts']:
|
if not in_ext in self.env['userland_in_exts']:
|
||||||
continue
|
continue
|
||||||
my_path_properties = path_properties.get(os.path.join(
|
in_path = os.path.join(path, in_filename)
|
||||||
self.env['userland_subdir'],
|
error = thread_pool.submit({
|
||||||
dirpath_relative_root,
|
'in_path': in_path,
|
||||||
in_filename
|
'out_path': self.resolve_userland_executable(in_path),
|
||||||
))
|
'cc_flags': cc_flags,
|
||||||
if my_path_properties.should_be_built(self.env):
|
'extra_objs_lkmc_common': [extra_obj_lkmc_common],
|
||||||
if dirpath_relative_root_components_len > 0:
|
'extra_objs_userland_asm': [extra_obj_userland_asm],
|
||||||
if dirpath_relative_root_components[0] == 'arch':
|
})
|
||||||
cc_flags_file.extend([
|
if error is not None:
|
||||||
'-I', os.path.join(self.env['userland_source_arch_arch_dir']), LF,
|
raise common.ExitLoop()
|
||||||
'-I', os.path.join(self.env['userland_source_arch_dir']), LF,
|
|
||||||
])
|
|
||||||
elif dirpath_relative_root_components[0] == 'libs':
|
|
||||||
if dirpath_relative_root_components_len > 1:
|
|
||||||
package_key = dirpath_relative_root_components[1]
|
|
||||||
if package_key in packages:
|
|
||||||
package = packages[package_key]
|
|
||||||
else:
|
|
||||||
package = {}
|
|
||||||
if 'cc_flags' in package:
|
|
||||||
cc_flags_file.extend(package['cc_flags'])
|
|
||||||
else:
|
|
||||||
pkg_config_output = subprocess.check_output([
|
|
||||||
self.env['pkg_config'],
|
|
||||||
'--cflags',
|
|
||||||
package_key
|
|
||||||
]).decode()
|
|
||||||
cc_flags_file.extend(self.sh.shlex_split(pkg_config_output))
|
|
||||||
if 'cc_flags_after' in package:
|
|
||||||
cc_flags_file.extend(package['cc_flags_after'])
|
|
||||||
else:
|
|
||||||
pkg_config_output = subprocess.check_output([
|
|
||||||
self.env['pkg_config'],
|
|
||||||
'--libs',
|
|
||||||
package_key
|
|
||||||
]).decode()
|
|
||||||
cc_flags_after.extend(self.sh.shlex_split(pkg_config_output))
|
|
||||||
if my_path_properties['cc_pedantic']:
|
|
||||||
cc_flags_file.extend(['-pedantic', LF])
|
|
||||||
common_objs_file = []
|
|
||||||
if my_path_properties['extra_objs_lkmc_common']:
|
|
||||||
common_objs_file.append(common_obj)
|
|
||||||
if my_path_properties['extra_objs_userland_asm']:
|
|
||||||
common_objs_file.append(common_obj_asm)
|
|
||||||
error = thread_pool.submit({
|
|
||||||
'c_std': my_path_properties['c_std'],
|
|
||||||
'cc_flags': cc_flags_file + my_path_properties['cc_flags'],
|
|
||||||
'cc_flags_after': cc_flags_after + my_path_properties['cc_flags_after'],
|
|
||||||
'cxx_std': my_path_properties['cxx_std'],
|
|
||||||
'extra_objs': common_objs_file,
|
|
||||||
'in_path': in_path,
|
|
||||||
'out_path': self.resolve_userland_executable(in_path),
|
|
||||||
})
|
|
||||||
if error is not None:
|
|
||||||
raise common.ExitLoop()
|
|
||||||
except common.ExitLoop:
|
except common.ExitLoop:
|
||||||
pass
|
pass
|
||||||
error = thread_pool.get_error()
|
error = thread_pool.get_error()
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ class PathProperties:
|
|||||||
'interactive': False,
|
'interactive': False,
|
||||||
# The script takes a perceptible amount of time to run. Possibly an infinite loop.
|
# The script takes a perceptible amount of time to run. Possibly an infinite loop.
|
||||||
'more_than_1s': False,
|
'more_than_1s': False,
|
||||||
|
# The path should not be built. E.g., it is symlinked into multiple archs.
|
||||||
|
'no_build': False,
|
||||||
# The path does not generate an executable in itself, e.g.
|
# The path does not generate an executable in itself, e.g.
|
||||||
# it only generates intermediate object files.
|
# it only generates intermediate object files. Therefore it
|
||||||
|
# should not be run while testing.
|
||||||
'no_executable': False,
|
'no_executable': False,
|
||||||
# the test receives a signal. We skip those tests for now,
|
# the test receives a signal. We skip those tests for now,
|
||||||
# on userland because we are lazy to figure out the exact semantics
|
# on userland because we are lazy to figure out the exact semantics
|
||||||
@@ -73,17 +76,21 @@ class PathProperties:
|
|||||||
def set_path_components(self, path_components):
|
def set_path_components(self, path_components):
|
||||||
self.path_components = path_components
|
self.path_components = path_components
|
||||||
|
|
||||||
def should_be_built(self, env):
|
def should_be_built(self, env, link=False):
|
||||||
if len(self.path_components) > 1 and \
|
if len(self.path_components) > 1 and \
|
||||||
self.path_components[1] == 'libs' and \
|
self.path_components[1] == 'libs' and \
|
||||||
not env['package_all'] and \
|
not env['package_all'] and \
|
||||||
not self.path_components[2] in env['package']:
|
not self.path_components[2] in env['package']:
|
||||||
return False
|
return False
|
||||||
return \
|
return \
|
||||||
not self['no_executable'] and \
|
not self['no_build'] and \
|
||||||
(
|
(
|
||||||
self['allowed_archs'] is None or
|
self['allowed_archs'] is None or
|
||||||
env['arch'] in self['allowed_archs']
|
env['arch'] in self['allowed_archs']
|
||||||
|
) and \
|
||||||
|
not (
|
||||||
|
link and
|
||||||
|
self['no_executable']
|
||||||
)
|
)
|
||||||
|
|
||||||
def should_be_tested(self, env):
|
def should_be_tested(self, env):
|
||||||
@@ -91,6 +98,7 @@ class PathProperties:
|
|||||||
self.should_be_built(env) and \
|
self.should_be_built(env) and \
|
||||||
not self['interactive'] and \
|
not self['interactive'] and \
|
||||||
not self['more_than_1s'] and \
|
not self['more_than_1s'] and \
|
||||||
|
not self['no_executable'] and \
|
||||||
not self['receives_signal'] and \
|
not self['receives_signal'] and \
|
||||||
not self['requires_argument'] and \
|
not self['requires_argument'] and \
|
||||||
not self['requires_kernel_modules'] and \
|
not self['requires_kernel_modules'] and \
|
||||||
@@ -256,9 +264,12 @@ path_properties_tuples = (
|
|||||||
'freestanding': freestanding_properties,
|
'freestanding': freestanding_properties,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
'empty.S': {'no_executable': True},
|
'empty.S': {'no_build': True},
|
||||||
'fail.S': {'no_executable': True},
|
'fail.S': {'no_build': True},
|
||||||
'main.c': {'no_executable': True},
|
'main.c': {
|
||||||
|
'extra_objs_userland_asm': False,
|
||||||
|
'no_executable': True
|
||||||
|
},
|
||||||
'x86_64': (
|
'x86_64': (
|
||||||
{'allowed_archs': {'x86_64'}},
|
{'allowed_archs': {'x86_64'}},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user