authorgravatar for alex_naskos@hotmail.comAlexandros Naskos <alex_naskos@hotmail.com> 2020-10-02 17:00:47+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-10-02 17:00:47+03:00
log55eb7c16c00d333837a9cc1472ca99fafd61a9b8
tree8a88ae7037e1616bb963c4e2cd763c227f364525
parentcd4c1ea790dff077cec3782f6e9c52fd58c5c6ba
parent84b6d2a80afe26c4b37550c89086cef2f6d066ab
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6494 from IridescentRose/emit-reloc-patch

Emit reloc patch

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

lib/std/build.zig+4
......@@ -1239,6 +1239,7 @@ pub const LibExeObjStep = struct {
12391239 /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF
12401240 /// file.
12411241 link_eh_frame_hdr: bool = false,
1242 link_emit_relocs: bool = false,
12421243
12431244 /// Place every function in its own section so that unused ones may be
12441245 /// safely garbage-collected during the linking phase.
......@@ -2075,6 +2076,9 @@ pub const LibExeObjStep = struct {
20752076 if (self.link_eh_frame_hdr) {
20762077 try zig_args.append("--eh-frame-hdr");
20772078 }
2079 if (self.link_emit_relocs) {
2080 try zig_args.append("--emit-relocs");
2081 }
20782082 if (self.link_function_sections) {
20792083 try zig_args.append("-ffunction-sections");
20802084 }
src/Compilation.zig+3
......@@ -352,6 +352,7 @@ pub const InitOptions = struct {
352352 time_report: bool = false,
353353 stack_report: bool = false,
354354 link_eh_frame_hdr: bool = false,
355 link_emit_relocs: bool = false,
355356 linker_script: ?[]const u8 = null,
356357 version_script: ?[]const u8 = null,
357358 override_soname: ?[]const u8 = null,
......@@ -447,6 +448,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
447448 options.system_libs.len != 0 or
448449 options.link_libc or options.link_libcpp or
449450 options.link_eh_frame_hdr or
451 options.link_emit_relocs or
450452 options.output_mode == .Lib or
451453 options.lld_argv.len != 0 or
452454 options.linker_script != null or options.version_script != null)
......@@ -769,6 +771,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
769771 .version_script = options.version_script,
770772 .gc_sections = options.linker_gc_sections,
771773 .eh_frame_hdr = options.link_eh_frame_hdr,
774 .emit_relocs = options.link_emit_relocs,
772775 .rdynamic = options.rdynamic,
773776 .extra_lld_args = options.lld_argv,
774777 .override_soname = options.override_soname,
src/link.zig+1
......@@ -60,6 +60,7 @@ pub const Options = struct {
6060 link_libcpp: bool,
6161 function_sections: bool,
6262 eh_frame_hdr: bool,
63 emit_relocs: bool,
6364 rdynamic: bool,
6465 z_nodelete: bool,
6566 z_defs: bool,
src/link/Elf.zig+5
......@@ -1286,6 +1286,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
12861286 man.hash.add(stack_size);
12871287 man.hash.add(gc_sections);
12881288 man.hash.add(self.base.options.eh_frame_hdr);
1289 man.hash.add(self.base.options.emit_relocs);
12891290 man.hash.add(self.base.options.rdynamic);
12901291 man.hash.addListOfBytes(self.base.options.extra_lld_args);
12911292 man.hash.addListOfBytes(self.base.options.lib_dirs);
......@@ -1364,6 +1365,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13641365 if (self.base.options.eh_frame_hdr) {
13651366 try argv.append("--eh-frame-hdr");
13661367 }
1368
1369 if (self.base.options.emit_relocs) {
1370 try argv.append("--emit-relocs");
1371 }
13671372
13681373 if (self.base.options.rdynamic) {
13691374 try argv.append("--export-dynamic");
src/main.zig+5
......@@ -273,6 +273,7 @@ const usage_build_generic =
273273 \\ -rdynamic Add all symbols to the dynamic symbol table
274274 \\ -rpath [path] Add directory to the runtime library search path
275275 \\ --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
276277 \\ -dynamic Force output to be dynamically linked
277278 \\ -static Force output to be statically linked
278279 \\ -Bsymbolic Bind global references locally
......@@ -438,6 +439,7 @@ fn buildOutputType(
438439 var use_lld: ?bool = null;
439440 var use_clang: ?bool = null;
440441 var link_eh_frame_hdr = false;
442 var link_emit_relocs = false;
441443 var each_lib_rpath = false;
442444 var libc_paths_file: ?[]const u8 = null;
443445 var machine_code_model: std.builtin.CodeModel = .default;
......@@ -838,6 +840,8 @@ fn buildOutputType(
838840 function_sections = true;
839841 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
840842 link_eh_frame_hdr = true;
843 } else if (mem.eql(u8, arg, "--emit-relocs")) {
844 link_emit_relocs = true;
841845 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
842846 linker_bind_global_refs_locally = true;
843847 } else if (mem.eql(u8, arg, "--verbose-link")) {
......@@ -1580,6 +1584,7 @@ fn buildOutputType(
15801584 .linker_z_nodelete = linker_z_nodelete,
15811585 .linker_z_defs = linker_z_defs,
15821586 .link_eh_frame_hdr = link_eh_frame_hdr,
1587 .link_emit_relocs = link_emit_relocs,
15831588 .stack_size_override = stack_size_override,
15841589 .strip = strip,
15851590 .single_threaded = single_threaded,