authorgravatar for iridescentrosesfall@gmail.comNathan Bourgeois <iridescentrosesfall@gmail.com> 2020-10-01 15:57:19-04:00
committergravatar for iridescentrosesfall@gmail.comNathan <iridescentrosesfall@gmail.com> 2020-10-01 17:04:04-04:00
log4566b273733be9508b6178742293008d8d66451e
tree0b7661f908845790eafdf8d2a3135f9a91d44080
parentbf0afaa876391571f6072650bf450356b26c928d

Patch in emit relocs support


5 files changed, 18 insertions(+), 0 deletions(-)

lib/std/build.zig+4
...@@ -1239,6 +1239,7 @@ pub const LibExeObjStep = struct {...@@ -1239,6 +1239,7 @@ pub const LibExeObjStep = struct {
1239 /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF1239 /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF
1240 /// file.1240 /// file.
1241 link_eh_frame_hdr: bool = false,1241 link_eh_frame_hdr: bool = false,
1242 link_emit_relocs: bool = false,
12421243
1243 /// Place every function in its own section so that unused ones may be1244 /// Place every function in its own section so that unused ones may be
1244 /// safely garbage-collected during the linking phase.1245 /// safely garbage-collected during the linking phase.
...@@ -2075,6 +2076,9 @@ pub const LibExeObjStep = struct {...@@ -2075,6 +2076,9 @@ pub const LibExeObjStep = struct {
2075 if (self.link_eh_frame_hdr) {2076 if (self.link_eh_frame_hdr) {
2076 try zig_args.append("--eh-frame-hdr");2077 try zig_args.append("--eh-frame-hdr");
2077 }2078 }
2079 if(self.link_emit_relocs){
2080 try zig_args.append("-emit-relocs");
2081 }
2078 if (self.link_function_sections) {2082 if (self.link_function_sections) {
2079 try zig_args.append("-ffunction-sections");2083 try zig_args.append("-ffunction-sections");
2080 }2084 }
src/Compilation.zig+3
...@@ -352,6 +352,7 @@ pub const InitOptions = struct {...@@ -352,6 +352,7 @@ pub const InitOptions = struct {
352 time_report: bool = false,352 time_report: bool = false,
353 stack_report: bool = false,353 stack_report: bool = false,
354 link_eh_frame_hdr: bool = false,354 link_eh_frame_hdr: bool = false,
355 link_emit_relocs: bool = false,
355 linker_script: ?[]const u8 = null,356 linker_script: ?[]const u8 = null,
356 version_script: ?[]const u8 = null,357 version_script: ?[]const u8 = null,
357 override_soname: ?[]const u8 = null,358 override_soname: ?[]const u8 = null,
...@@ -447,6 +448,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -447,6 +448,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
447 options.system_libs.len != 0 or448 options.system_libs.len != 0 or
448 options.link_libc or options.link_libcpp or449 options.link_libc or options.link_libcpp or
449 options.link_eh_frame_hdr or450 options.link_eh_frame_hdr or
451 options.link_emit_relocs or
450 options.output_mode == .Lib or452 options.output_mode == .Lib or
451 options.lld_argv.len != 0 or453 options.lld_argv.len != 0 or
452 options.linker_script != null or options.version_script != null)454 options.linker_script != null or options.version_script != null)
...@@ -769,6 +771,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -769,6 +771,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
769 .version_script = options.version_script,771 .version_script = options.version_script,
770 .gc_sections = options.linker_gc_sections,772 .gc_sections = options.linker_gc_sections,
771 .eh_frame_hdr = options.link_eh_frame_hdr,773 .eh_frame_hdr = options.link_eh_frame_hdr,
774 .emit_relocs = options.link_emit_relocs,
772 .rdynamic = options.rdynamic,775 .rdynamic = options.rdynamic,
773 .extra_lld_args = options.lld_argv,776 .extra_lld_args = options.lld_argv,
774 .override_soname = options.override_soname,777 .override_soname = options.override_soname,
src/link.zig+1
...@@ -60,6 +60,7 @@ pub const Options = struct {...@@ -60,6 +60,7 @@ pub const Options = struct {
60 link_libcpp: bool,60 link_libcpp: bool,
61 function_sections: bool,61 function_sections: bool,
62 eh_frame_hdr: bool,62 eh_frame_hdr: bool,
63 emit_relocs: bool,
63 rdynamic: bool,64 rdynamic: bool,
64 z_nodelete: bool,65 z_nodelete: bool,
65 z_defs: bool,66 z_defs: bool,
src/link/Elf.zig+5
...@@ -1286,6 +1286,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1286,6 +1286,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1286 man.hash.add(stack_size);1286 man.hash.add(stack_size);
1287 man.hash.add(gc_sections);1287 man.hash.add(gc_sections);
1288 man.hash.add(self.base.options.eh_frame_hdr);1288 man.hash.add(self.base.options.eh_frame_hdr);
1289 man.hash.add(self.base.options.emit_relocs);
1289 man.hash.add(self.base.options.rdynamic);1290 man.hash.add(self.base.options.rdynamic);
1290 man.hash.addListOfBytes(self.base.options.extra_lld_args);1291 man.hash.addListOfBytes(self.base.options.extra_lld_args);
1291 man.hash.addListOfBytes(self.base.options.lib_dirs);1292 man.hash.addListOfBytes(self.base.options.lib_dirs);
...@@ -1364,6 +1365,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1364,6 +1365,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1364 if (self.base.options.eh_frame_hdr) {1365 if (self.base.options.eh_frame_hdr) {
1365 try argv.append("--eh-frame-hdr");1366 try argv.append("--eh-frame-hdr");
1366 }1367 }
1368
1369 if (self.base.options.emit_relocs) {
1370 try argv.append("-emit-relocs");
1371 }
13671372
1368 if (self.base.options.rdynamic) {1373 if (self.base.options.rdynamic) {
1369 try argv.append("--export-dynamic");1374 try argv.append("--export-dynamic");
src/main.zig+5
...@@ -273,6 +273,7 @@ const usage_build_generic =...@@ -273,6 +273,7 @@ const usage_build_generic =
273 \\ -rdynamic Add all symbols to the dynamic symbol table273 \\ -rdynamic Add all symbols to the dynamic symbol table
274 \\ -rpath [path] Add directory to the runtime library search path274 \\ -rpath [path] Add directory to the runtime library search path
275 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker275 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
276 \\ -emit-relocs Enable output of relocation sections for post build tools
276 \\ -dynamic Force output to be dynamically linked277 \\ -dynamic Force output to be dynamically linked
277 \\ -static Force output to be statically linked278 \\ -static Force output to be statically linked
278 \\ -Bsymbolic Bind global references locally279 \\ -Bsymbolic Bind global references locally
...@@ -438,6 +439,7 @@ fn buildOutputType(...@@ -438,6 +439,7 @@ fn buildOutputType(
438 var use_lld: ?bool = null;439 var use_lld: ?bool = null;
439 var use_clang: ?bool = null;440 var use_clang: ?bool = null;
440 var link_eh_frame_hdr = false;441 var link_eh_frame_hdr = false;
442 var link_emit_relocs = false;
441 var each_lib_rpath = false;443 var each_lib_rpath = false;
442 var libc_paths_file: ?[]const u8 = null;444 var libc_paths_file: ?[]const u8 = null;
443 var machine_code_model: std.builtin.CodeModel = .default;445 var machine_code_model: std.builtin.CodeModel = .default;
...@@ -838,6 +840,8 @@ fn buildOutputType(...@@ -838,6 +840,8 @@ fn buildOutputType(
838 function_sections = true;840 function_sections = true;
839 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {841 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
840 link_eh_frame_hdr = true;842 link_eh_frame_hdr = true;
843 } else if (mem.eql(u8, arg, "-emit-relocs")) {
844 link_emit_relocs = true;
841 } else if (mem.eql(u8, arg, "-Bsymbolic")) {845 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
842 linker_bind_global_refs_locally = true;846 linker_bind_global_refs_locally = true;
843 } else if (mem.eql(u8, arg, "--verbose-link")) {847 } else if (mem.eql(u8, arg, "--verbose-link")) {
...@@ -1580,6 +1584,7 @@ fn buildOutputType(...@@ -1580,6 +1584,7 @@ fn buildOutputType(
1580 .linker_z_nodelete = linker_z_nodelete,1584 .linker_z_nodelete = linker_z_nodelete,
1581 .linker_z_defs = linker_z_defs,1585 .linker_z_defs = linker_z_defs,
1582 .link_eh_frame_hdr = link_eh_frame_hdr,1586 .link_eh_frame_hdr = link_eh_frame_hdr,
1587 .link_emit_relocs = link_emit_relocs,
1583 .stack_size_override = stack_size_override,1588 .stack_size_override = stack_size_override,
1584 .strip = strip,1589 .strip = strip,
1585 .single_threaded = single_threaded,1590 .single_threaded = single_threaded,