diff --git a/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py b/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py index 5f534b044ef7..7d20c0a49e0a 100644 --- a/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py +++ b/python/mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py @@ -170,11 +170,33 @@ class TestToolkitMozConfigure(BaseConfigureTest): ) PACK = ["-Wl,-z,pack-relative-relocs"] + # The typical case with a bootstrap build: linker supports pack-relative-relocs, + # but glibc is old and doesn't. + mockcc = MockCC(True, False) + readelf = ReadElf(True) + self.assertEqual(get_values(mockcc, readelf), ("lld", None, "relr")) + self.assertEqual( + get_values(mockcc, readelf, ["--enable-release"]), ("lld", None, "relr") + ) + self.assertEqual( + get_values(mockcc, readelf, ["--enable-elf-hack"]), ("lld", None, "relr") + ) + self.assertEqual( + get_values(mockcc, readelf, ["--enable-elf-hack=relr"]), + ("lld", None, "relr"), + ) + # LLD is picked by default and enabling elfhack fails because of that. + with self.assertRaises(SystemExit): + get_values(mockcc, readelf, ["--enable-elf-hack=legacy"]) + # If we force to use BFD ld, it works. + self.assertEqual( + get_values( + mockcc, readelf, ["--enable-elf-hack=legacy", "--enable-linker=bfd"] + ), + ("bfd", None, "legacy"), + ) + for mockcc, readelf in ( - # The typical case with a bootstrap build: linker supports pack-relative-relocs, - # but glibc is old and doesn't. We won't use pack-relative-relocs, and will use - # elfhack on release builds, or when explicitly enabled. - (MockCC(True, False), ReadElf(True)), # Linker doesn't support pack-relative-relocs. Glibc is old. (MockCC(False, False), ReadElf(False)), # Linker doesn't support pack-relative-relocs. Glibc is new. @@ -189,21 +211,13 @@ class TestToolkitMozConfigure(BaseConfigureTest): get_values(mockcc, readelf, ["--enable-release"]), ("lld", None, None), ) - # LLD is picked by default and enabling elfhack fails because of that. with self.assertRaises(SystemExit): get_values(mockcc, readelf, ["--enable-elf-hack"]) + with self.assertRaises(SystemExit): + get_values(mockcc, readelf, ["--enable-elf-hack=relr"]) + # LLD is picked by default and enabling elfhack fails because of that. with self.assertRaises(SystemExit): get_values(mockcc, readelf, ["--enable-elf-hack=legacy"]) - if readelf.with_relr: - # Explicitly enabling relrhack works because pack-relative-relocs are supported. - self.assertEqual( - get_values(mockcc, readelf, ["--enable-elf-hack=relr"]), - ("lld", None, "relr"), - ) - else: - # relrhack doesn't work without pack-relative-relocs support. - with self.assertRaises(SystemExit): - get_values(mockcc, readelf, ["--enable-elf-hack=relr"]) # If we force to use BFD ld, it works. self.assertEqual( get_values( @@ -226,15 +240,21 @@ class TestToolkitMozConfigure(BaseConfigureTest): self.assertEqual( get_values(mockcc, readelf, ["--enable-release"]), ("lld", PACK, None) ) + self.assertEqual( + get_values(mockcc, readelf, ["--enable-elf-hack"]), + ("lld", None, "relr"), + ) + self.assertEqual( + get_values(mockcc, readelf, ["--enable-elf-hack=relr"]), + ("lld", None, "relr"), + ) # LLD is picked by default and enabling elfhack fails because of that. - with self.assertRaises(SystemExit): - get_values(mockcc, readelf, ["--enable-elf-hack"]) with self.assertRaises(SystemExit): get_values(mockcc, readelf, ["--enable-elf-hack=legacy"]) # If we force to use BFD ld, it works. self.assertEqual( get_values(mockcc, readelf, ["--enable-elf-hack", "--enable-linker=bfd"]), - ("bfd", None, "legacy"), + ("bfd", None, "relr"), ) self.assertEqual( get_values( @@ -242,11 +262,6 @@ class TestToolkitMozConfigure(BaseConfigureTest): ), ("bfd", None, "legacy"), ) - # Explicitly enabling relrhack works because pack-relative-relocs are supported. - self.assertEqual( - get_values(mockcc, readelf, ["--enable-elf-hack=relr"]), - ("lld", None, "relr"), - ) if __name__ == "__main__": diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 6db3501c20a8..9d5ee0ca9100 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -1498,14 +1498,9 @@ with only_when("--enable-compile-environment"): if enable and enable != ("relr",): return enable - @depends("--enable-elf-hack", "MOZ_AUTOMATION", when=has_elfhack) - def may_enable_relrhack(enable, automation): - # For now, only enable relrhack when explicitly given with - # --enable-elf-hack=relr. On automation, we automatically - # enable it when possible. - if automation and enable and enable != ("legacy",): - return enable - if enable == ("relr",): + @depends("--enable-elf-hack", when=has_elfhack) + def may_enable_relrhack(enable): + if enable and enable != ("legacy",): return enable @depends(