authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-28 00:53:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-28 00:53:05-07:00
log4b1fe8e49238514217e1c6900361a4eb8a0dadbd
tree2b294605aa0b9ecba0a3e4f5a2502fb95b3a0513
parentab36a162d07ee66724bd369e2b19b81ae6fba6ea

glibc: clang 12 assembler regression workaround

Our glibc stub assembly file looked something like this: ``` .globl _Exit_2_2_5 .type _Exit_2_2_5, %function; .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5 .hidden _Exit_2_2_5 _Exit_2_2_5: ``` With clang 12, the shared objects this produced stopped having any exported symbols. When I removed the `.hidden` directive, it resolved the issue, however, there are now unwanted exports: ``` $ readelf -W --dyn-syms libc.so.6 | grep sys_errlist 139: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist_GLIBC_2_3 147: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist_GLIBC_2_4 395: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist_GLIBC_2_2_5 487: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist_GLIBC_2_2_5 1266: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist@@GLIBC_2.12 1267: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist@GLIBC_2.2.5 1268: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist@GLIBC_2.3 1269: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 _sys_errlist@GLIBC_2.4 2137: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist@@GLIBC_2.12 2138: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist@GLIBC_2.2.5 2139: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist@GLIBC_2.3 2140: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist@GLIBC_2.4 2156: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist_GLIBC_2_3 2161: 000000000001ee08 0 FUNC GLOBAL DEFAULT 7 sys_errlist_GLIBC_2_4 ``` Every line here without an `@` symbol is an unwanted export. Before, the unwanted ones had LOCAL HIDDEN linkage. As a mitigation, I did two things: * Added `_GLIBC_` to the unwanted exports so that they would not conflict with anything. * Made the default export (the `@@` one) the bare symbol name. This appears to reduce the unwanted exports to only symbols that have more than one symbol (which is still quite many). This will unblock progress on this branch, however, there is now a new issue to solve, that the provided glibc stub .so files have too many symbols exported. We will have to find a way to avoid this.

1 files changed, 18 insertions(+), 18 deletions(-)

src/glibc.zig+18-18
...@@ -807,26 +807,26 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -807,26 +807,26 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
807 // .globl _Exit_2_2_5807 // .globl _Exit_2_2_5
808 // .type _Exit_2_2_5, %function;808 // .type _Exit_2_2_5, %function;
809 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5809 // .symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
810 // .hidden _Exit_2_2_5
811 // _Exit_2_2_5:810 // _Exit_2_2_5:
812 const ver_index = ver_list.versions[ver_i];811 const ver_index = ver_list.versions[ver_i];
813 const ver = metadata.all_versions[ver_index];812 const ver = metadata.all_versions[ver_index];
814 const sym_name = libc_fn.name;813 const sym_name = libc_fn.name;
815 // Default symbol version definition vs normal symbol version definition814 // Default symbol version definition vs normal symbol version definition
816 const want_two_ats = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;815 const want_default = chosen_def_ver_index != 255 and ver_index == chosen_def_ver_index;
817 const at_sign_str = "@@"[0 .. @boolToInt(want_two_ats) + @as(usize, 1)];816 const at_sign_str: []const u8 = if (want_default) "@@" else "@";
818
819 if (ver.patch == 0) {817 if (ver.patch == 0) {
820 const sym_plus_ver = try std.fmt.allocPrint(818 const sym_plus_ver = if (want_default)
821 arena,819 sym_name
822 "{s}_{d}_{d}",820 else
823 .{ sym_name, ver.major, ver.minor },821 try std.fmt.allocPrint(
824 );822 arena,
823 "{s}_GLIBC_{d}_{d}",
824 .{ sym_name, ver.major, ver.minor },
825 );
825 try zig_body.writer().print(826 try zig_body.writer().print(
826 \\.globl {s}827 \\.globl {s}
827 \\.type {s}, %function;828 \\.type {s}, %function;
828 \\.symver {s}, {s}{s}GLIBC_{d}.{d}829 \\.symver {s}, {s}{s}GLIBC_{d}.{d}
829 \\.hidden {s}
830 \\{s}:830 \\{s}:
831 \\831 \\
832 , .{832 , .{
...@@ -838,19 +838,20 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -838,19 +838,20 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
838 ver.major,838 ver.major,
839 ver.minor,839 ver.minor,
840 sym_plus_ver,840 sym_plus_ver,
841 sym_plus_ver,
842 });841 });
843 } else {842 } else {
844 const sym_plus_ver = try std.fmt.allocPrint(843 const sym_plus_ver = if (want_default)
845 arena,844 sym_name
846 "{s}_{d}_{d}_{d}",845 else
847 .{ sym_name, ver.major, ver.minor, ver.patch },846 try std.fmt.allocPrint(
848 );847 arena,
848 "{s}_GLIBC_{d}_{d}_{d}",
849 .{ sym_name, ver.major, ver.minor, ver.patch },
850 );
849 try zig_body.writer().print(851 try zig_body.writer().print(
850 \\.globl {s}852 \\.globl {s}
851 \\.type {s}, %function;853 \\.type {s}, %function;
852 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}854 \\.symver {s}, {s}{s}GLIBC_{d}.{d}.{d}
853 \\.hidden {s}
854 \\{s}:855 \\{s}:
855 \\856 \\
856 , .{857 , .{
...@@ -863,7 +864,6 @@ pub fn buildSharedObjects(comp: *Compilation) !void {...@@ -863,7 +864,6 @@ pub fn buildSharedObjects(comp: *Compilation) !void {
863 ver.minor,864 ver.minor,
864 ver.patch,865 ver.patch,
865 sym_plus_ver,866 sym_plus_ver,
866 sym_plus_ver,
867 });867 });
868 }868 }
869 }869 }