Commit 54e3b619 authored by Sang Ik Lee's avatar Sang Ik Lee Committed by Scott Cyphers

Add required compiler and linker flags to meet sequrity requirements. (#666)

* Add required compiler and linker flags to meet sequrity requirements.

* Update compiler and linker flags for building python wrapper.
parent 3b981907
...@@ -209,21 +209,32 @@ ext_modules = [Extension( ...@@ -209,21 +209,32 @@ ext_modules = [Extension(
class BuildExt(build_ext): class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options.""" """
A custom build extension for adding compiler-specific options.
"""
def build_extensions(self): def build_extensions(self):
ct = self.compiler.compiler_type
for ext in self.extensions: for ext in self.extensions:
ext.extra_compile_args += [cpp_flag(self.compiler)] ext.extra_compile_args += [cpp_flag(self.compiler)]
ext.extra_compile_args += ['-w'] if has_flag(self.compiler, '-fstack-protector-strong'):
ext.extra_compile_args += ['-fstack-protector-strong']
else:
ext.extra_compile_args += ['-fstack-protector']
if has_flag(self.compiler, '-frtti'): if has_flag(self.compiler, '-frtti'):
ext.extra_compile_args += ['-frtti'] ext.extra_compile_args += ['-frtti']
if sys.platform == 'darwin': if sys.platform == 'darwin':
ext.extra_compile_args += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] ext.extra_compile_args += ['-stdlib=libc++', '-mmacosx-version-min=10.7']
ext.extra_link_args += ['-Wl,-rpath,@loader_path/../..'] ext.extra_link_args += ["-Wl,-rpath,@loader_path/../.."]
else: else:
if has_flag(self.compiler, '-fvisibility=hidden'): if has_flag(self.compiler, '-fvisibility=hidden'):
ext.extra_compile_args += ['-fvisibility=hidden'] ext.extra_compile_args += ['-fvisibility=hidden']
ext.extra_link_args += ['-Wl,-rpath,$ORIGIN/../..'] ext.extra_link_args += ['-Wl,-rpath,$ORIGIN/../..']
if sys.platform != 'darwin':
ext.extra_link_args += ['-z', 'noexecstack']
ext.extra_link_args += ['-z', 'relro']
ext.extra_link_args += ['-z', 'now']
ext.extra_compile_args += ['-Wformat', '-Wformat-security']
ext.extra_compile_args += ['-O2', '-D_FORTIFY_SOURCE=2']
build_ext.build_extensions(self) build_ext.build_extensions(self)
......
...@@ -226,6 +226,10 @@ class BuildExt(build_ext): ...@@ -226,6 +226,10 @@ class BuildExt(build_ext):
ct = self.compiler.compiler_type ct = self.compiler.compiler_type
for ext in self.extensions: for ext in self.extensions:
ext.extra_compile_args += [cpp_flag(self.compiler)] ext.extra_compile_args += [cpp_flag(self.compiler)]
if has_flag(self.compiler, '-fstack-protector-strong'):
ext.extra_compile_args += ['-fstack-protector-strong']
else:
ext.extra_compile_args += ['-fstack-protector']
if has_flag(self.compiler, '-frtti'): if has_flag(self.compiler, '-frtti'):
ext.extra_compile_args += ['-frtti'] ext.extra_compile_args += ['-frtti']
if sys.platform == 'darwin': if sys.platform == 'darwin':
...@@ -234,7 +238,13 @@ class BuildExt(build_ext): ...@@ -234,7 +238,13 @@ class BuildExt(build_ext):
else: else:
if has_flag(self.compiler, '-fvisibility=hidden'): if has_flag(self.compiler, '-fvisibility=hidden'):
ext.extra_compile_args += ['-fvisibility=hidden'] ext.extra_compile_args += ['-fvisibility=hidden']
ext.extra_link_args += ["-Wl,-rpath,$ORIGIN/../.."] ext.extra_link_args += ['-Wl,-rpath,$ORIGIN/../..']
if sys.platform != 'darwin':
ext.extra_link_args += ['-z', 'noexecstack']
ext.extra_link_args += ['-z', 'relro']
ext.extra_link_args += ['-z', 'now']
ext.extra_compile_args += ['-Wformat', '-Wformat-security']
ext.extra_compile_args += ['-O2', '-D_FORTIFY_SOURCE=2']
build_ext.build_extensions(self) build_ext.build_extensions(self)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment