Skip to content

Commit 7b20a00

Browse files
committed
(PA-6383) Enable PIE for Ubuntu and Debian
(PA-6383) Exclude ppc64 architecture (PA-6383) Fix Spaces (PA-6383) Exclude ppc64 arch (PA-6383) created compiler setting separately (PA-6383) Changes to runtime-bolt (PA-6383) Exclude EL platforms
1 parent 9833ad9 commit 7b20a00

7 files changed

+33
-21
lines changed

configs/components/_base-ruby.rb

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
elsif platform.architecture == 'arm64' && platform.os_version.to_i >= 13
7777
pkg.environment 'CC', 'clang'
7878
end
79+
elsif settings[:supports_pie]
80+
pkg.environment 'LDFLAGS', settings[:ldflags]
81+
pkg.environment 'optflags', settings[:cflags]
7982
end
8083

8184
####################

configs/components/augeas.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
end
120120
end
121121

122-
if platform.name =~ /sles-15|el-8|debian-10/ || platform.is_fedora?
122+
if settings[:supports_pie]
123123
pkg.environment 'CFLAGS', settings[:cflags]
124124
pkg.environment 'CPPFLAGS', settings[:cppflags]
125125
pkg.environment "LDFLAGS", settings[:ldflags]

configs/components/ruby-2.7.8.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
special_flags = " --prefix=#{ruby_dir} --with-opt-dir=#{settings[:prefix]} "
102102

103-
if platform.name =~ /sles-15|el-8|debian-10/
103+
if settings[:supports_pie]
104104
special_flags += " CFLAGS='#{settings[:cflags]}' LDFLAGS='#{settings[:ldflags]}' CPPFLAGS='#{settings[:cppflags]}' "
105105
end
106106

configs/components/ruby-3.2.5.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
special_flags = " --prefix=#{ruby_dir} --with-opt-dir=#{settings[:prefix]} "
9595

96-
if platform.name =~ /sles-15|el-8|debian-10/
96+
if settings[:supports_pie]
9797
special_flags += " CFLAGS='#{settings[:cflags]}' LDFLAGS='#{settings[:ldflags]}' CPPFLAGS='#{settings[:cppflags]}' "
9898
end
9999

configs/components/runtime-bolt.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
pkg.install_file "#{settings[:tools_root]}/bin/libgdbm_compat-4.dll", "#{settings[:ruby_bindir]}/libgdbm_compat-4.dll"
1414
pkg.install_file "#{settings[:tools_root]}/bin/libiconv-2.dll", "#{settings[:ruby_bindir]}/libiconv-2.dll"
1515
pkg.install_file "#{settings[:tools_root]}/bin/libffi-6.dll", "#{settings[:ruby_bindir]}/libffi-6.dll"
16-
elsif platform.is_macos? or platform.name =~ /sles-15|el-8|debian-10|ubuntu-20.04|ubuntu-22.04/ || platform.is_fedora?
16+
elsif settings[:supports_pie]
1717

1818
# Do nothing for distros that have a suitable compiler do not use pl-build-tools
1919

configs/projects/_shared-agent-settings.rb

+2-17
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,8 @@
140140
proj.setting(:platform_triple, platform_triple)
141141
proj.setting(:host, host)
142142

143-
# Define default CFLAGS and LDFLAGS for most platforms, and then
144-
# tweak or adjust them as needed.
145-
proj.setting(:cppflags, "-I#{proj.includedir} -I/opt/pl-build-tools/include")
146-
proj.setting(:cflags, "#{proj.cppflags}")
147-
proj.setting(:ldflags, "-L#{proj.libdir} -L/opt/pl-build-tools/lib -Wl,-rpath=#{proj.libdir}")
148-
149-
# Platform specific overrides or settings, which may override the defaults
150-
151-
# Harden Linux ELF binaries by compiling with PIE (Position Independent Executables) support,
152-
# stack canary and full RELRO.
153-
# We only do this on platforms that use their default OS toolchain since pl-gcc versions
154-
# are too old to support these flags.
155-
if platform.name =~ /sles-15|el-8|debian-10/ || platform.is_fedora?
156-
proj.setting(:cppflags, "-I#{proj.includedir} -D_FORTIFY_SOURCE=2")
157-
proj.setting(:cflags, '-fstack-protector-strong -fno-plt -O2')
158-
proj.setting(:ldflags, "-L#{proj.libdir} -Wl,-rpath=#{proj.libdir},-z,relro,-z,now")
159-
end
143+
# Load default compiler settings
144+
instance_eval File.read('configs/projects/_shared-compiler-settings.rb')
160145

161146
if ruby_version_x == "3"
162147
proj.setting(:openssl_version, '3.0')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Define default CFLAGS and LDFLAGS for most platforms, and then
2+
# tweak or adjust them as needed.
3+
proj.setting(:cppflags, "-I#{proj.includedir} -I/opt/pl-build-tools/include")
4+
proj.setting(:cflags, "#{proj.cppflags}")
5+
proj.setting(:ldflags, "-L#{proj.libdir} -L/opt/pl-build-tools/lib -Wl,-rpath=#{proj.libdir}")
6+
7+
# Platform specific overrides or settings, which may override the defaults
8+
9+
# Harden Linux ELF binaries by compiling with PIE (Position Independent Executables) support,
10+
# stack canary and full RELRO.
11+
# We only do this on platforms that use their default OS toolchain since pl-gcc versions
12+
# are too old to support these flags.
13+
14+
if((platform.is_sles? && platform.os_version.to_i >= 15) ||
15+
(platform.is_el? && platform.os_version.to_i == 8 && platform.architecture !~ /ppc64/) ||
16+
(platform.is_debian? && platform.os_version.to_i >= 10) ||
17+
(platform.is_ubuntu? && platform.os_version.to_i >= 22) ||
18+
platform.is_fedora?
19+
)
20+
proj.setting(:supports_pie, true)
21+
proj.setting(:cppflags, "-I#{proj.includedir} -D_FORTIFY_SOURCE=2")
22+
proj.setting(:cflags, '-fstack-protector-strong -fno-plt -O2')
23+
proj.setting(:ldflags, "-L#{proj.libdir} -Wl,-rpath=#{proj.libdir},-z,relro,-z,now")
24+
end

0 commit comments

Comments
 (0)