| ... | @@ -1884,6 +1884,16 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -1884,6 +1884,16 @@ fn initSyntheticSections(self: *Elf) !void { |
| 1884 | const ptr_size = self.ptrWidthBytes(); | 1884 | const ptr_size = self.ptrWidthBytes(); |
| 1885 | const shared_objects = self.shared_objects.values(); | 1885 | const shared_objects = self.shared_objects.values(); |
| 1886 | | 1886 | |
| | 1887 | const is_exe_or_dyn_lib = switch (comp.config.output_mode) { |
| | 1888 | .Exe => true, |
| | 1889 | .Lib => comp.config.link_mode == .dynamic, |
| | 1890 | .Obj => false, |
| | 1891 | }; |
| | 1892 | const have_dynamic_linker = comp.config.link_mode == .dynamic and is_exe_or_dyn_lib and !target.dynamic_linker.eql(.none); |
| | 1893 | |
| | 1894 | const needs_interp = have_dynamic_linker and |
| | 1895 | (comp.config.link_libc or comp.root_mod.resolved_target.is_explicit_dynamic_linker); |
| | 1896 | |
| 1887 | const needs_eh_frame = blk: { | 1897 | const needs_eh_frame = blk: { |
| 1888 | if (self.zigObjectPtr()) |zo| | 1898 | if (self.zigObjectPtr()) |zo| |
| 1889 | if (zo.eh_frame_index != null) break :blk true; | 1899 | if (zo.eh_frame_index != null) break :blk true; |
| ... | @@ -1891,6 +1901,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -1891,6 +1901,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 1891 | if (self.file(index).?.object.cies.items.len > 0) break true; | 1901 | if (self.file(index).?.object.cies.items.len > 0) break true; |
| 1892 | } else false; | 1902 | } else false; |
| 1893 | }; | 1903 | }; |
| | 1904 | |
| 1894 | if (needs_eh_frame) { | 1905 | if (needs_eh_frame) { |
| 1895 | if (self.section_indexes.eh_frame == null) { | 1906 | if (self.section_indexes.eh_frame == null) { |
| 1896 | self.section_indexes.eh_frame = self.sectionByName(".eh_frame") orelse try self.addSection(.{ | 1907 | self.section_indexes.eh_frame = self.sectionByName(".eh_frame") orelse try self.addSection(.{ |
| ... | @@ -1922,13 +1933,17 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -1922,13 +1933,17 @@ fn initSyntheticSections(self: *Elf) !void { |
| 1922 | }); | 1933 | }); |
| 1923 | } | 1934 | } |
| 1924 | | 1935 | |
| 1925 | if (self.section_indexes.got_plt == null) { | 1936 | if (have_dynamic_linker) { |
| 1926 | self.section_indexes.got_plt = try self.addSection(.{ | 1937 | if (self.section_indexes.got_plt == null) { |
| 1927 | .name = try self.insertShString(".got.plt"), | 1938 | self.section_indexes.got_plt = try self.addSection(.{ |
| 1928 | .type = elf.SHT_PROGBITS, | 1939 | .name = try self.insertShString(".got.plt"), |
| 1929 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 1940 | .type = elf.SHT_PROGBITS, |
| 1930 | .addralign = @alignOf(u64), | 1941 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 1931 | }); | 1942 | .addralign = @alignOf(u64), |
| | 1943 | }); |
| | 1944 | } |
| | 1945 | } else { |
| | 1946 | assert(self.plt.symbols.items.len == 0); |
| 1932 | } | 1947 | } |
| 1933 | | 1948 | |
| 1934 | const needs_rela_dyn = blk: { | 1949 | const needs_rela_dyn = blk: { |
| ... | @@ -1989,16 +2004,6 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -1989,16 +2004,6 @@ fn initSyntheticSections(self: *Elf) !void { |
| 1989 | }); | 2004 | }); |
| 1990 | } | 2005 | } |
| 1991 | | 2006 | |
| 1992 | const is_exe_or_dyn_lib = switch (comp.config.output_mode) { | | |
| 1993 | .Exe => true, | | |
| 1994 | .Lib => comp.config.link_mode == .dynamic, | | |
| 1995 | .Obj => false, | | |
| 1996 | }; | | |
| 1997 | const have_dynamic_linker = comp.config.link_mode == .dynamic and is_exe_or_dyn_lib and !target.dynamic_linker.eql(.none); | | |
| 1998 | | | |
| 1999 | const needs_interp = have_dynamic_linker and | | |
| 2000 | (comp.config.link_libc or comp.root_mod.resolved_target.is_explicit_dynamic_linker); | | |
| 2001 | | | |
| 2002 | if (needs_interp and self.section_indexes.interp == null) { | 2007 | if (needs_interp and self.section_indexes.interp == null) { |
| 2003 | self.section_indexes.interp = try self.addSection(.{ | 2008 | self.section_indexes.interp = try self.addSection(.{ |
| 2004 | .name = try self.insertShString(".interp"), | 2009 | .name = try self.insertShString(".interp"), |