diff options
| author | Kenta Iwasaki <kenta@lithdew.net> | 2021-10-29 18:03:55 +0900 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-29 19:18:44 -0400 |
| commit | 2cdffc97f062feb898f4c8268f1ec6e252077e96 (patch) | |
| tree | 4e173d722842737d1e995592f45d9e8577fbd091 /src/main.zig | |
| parent | 83a4bb6e6957325b744a08e16cab6b2a4a045f3e (diff) | |
| download | zig-2cdffc97f062feb898f4c8268f1ec6e252077e96.tar.gz zig-2cdffc97f062feb898f4c8268f1ec6e252077e96.zip | |
zig: expose linker options and include '-z notext'
Add an option to allow the '-z notext' option to be passed to the linker
via. the compiler frontend, which is a flag that tells the linker that
relocations in read-only sections are permitted. Certain targets such as
Solana BPF rely on this flag.
Expose all linker options i.e. '-z nodelete', '-z now', '-z relro' in
the compiler frontend. Usage documentation has been updated accordingly.
Expose the '-z notext' flag in the standard library build runner.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig index afe5e324c2..f3837ef734 100644 --- a/src/main.zig +++ b/src/main.zig @@ -401,6 +401,14 @@ const usage_build_generic = \\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker \\ --emit-relocs Enable output of relocation sections for post build tools + \\ -z [arg] Append linker arguments + \\ nodelete Indicate that the object cannot be deleted from a process + \\ notext Permit read-only relocations in read-only segments + \\ defs Force a fatal error if any undefined symbols remain + \\ origin Indicate that the object must have its origin processed + \\ noexecstack Indicate that the object requires an executable stack + \\ now Force all relocations to be processed on load + \\ relro Force all relocations to be resolved and be read-only on load \\ -dynamic Force output to be dynamically linked \\ -static Force output to be statically linked \\ -Bsymbolic Bind global references locally @@ -595,6 +603,7 @@ fn buildOutputType( var linker_allow_shlib_undefined: ?bool = null; var linker_bind_global_refs_locally: ?bool = null; var linker_z_nodelete = false; + var linker_z_notext = false; var linker_z_defs = false; var linker_z_origin = false; var linker_z_noexecstack = false; @@ -1086,6 +1095,29 @@ fn buildOutputType( linker_allow_shlib_undefined = true; } else if (mem.eql(u8, arg, "-fno-allow-shlib-undefined")) { linker_allow_shlib_undefined = false; + } else if (mem.eql(u8, arg, "-z")) { + i += 1; + if (i >= args.len) { + fatal("expected linker arg after '{s}'", .{arg}); + } + const z_arg = args[i]; + if (mem.eql(u8, z_arg, "nodelete")) { + linker_z_nodelete = true; + } else if (mem.eql(u8, z_arg, "notext")) { + linker_z_notext = true; + } else if (mem.eql(u8, z_arg, "defs")) { + linker_z_defs = true; + } else if (mem.eql(u8, z_arg, "origin")) { + linker_z_origin = true; + } else if (mem.eql(u8, z_arg, "noexecstack")) { + linker_z_noexecstack = true; + } else if (mem.eql(u8, z_arg, "now")) { + linker_z_now = true; + } else if (mem.eql(u8, z_arg, "relro")) { + linker_z_relro = true; + } else { + warn("unsupported linker arg: -z {s}", .{z_arg}); + } } else if (mem.eql(u8, arg, "-Bsymbolic")) { linker_bind_global_refs_locally = true; } else if (mem.eql(u8, arg, "--debug-compile-errors")) { @@ -1422,6 +1454,8 @@ fn buildOutputType( const z_arg = linker_args.items[i]; if (mem.eql(u8, z_arg, "nodelete")) { linker_z_nodelete = true; + } else if (mem.eql(u8, z_arg, "notext")) { + linker_z_notext = true; } else if (mem.eql(u8, z_arg, "defs")) { linker_z_defs = true; } else if (mem.eql(u8, z_arg, "origin")) { @@ -2108,6 +2142,7 @@ fn buildOutputType( .linker_allow_shlib_undefined = linker_allow_shlib_undefined, .linker_bind_global_refs_locally = linker_bind_global_refs_locally, .linker_z_nodelete = linker_z_nodelete, + .linker_z_notext = linker_z_notext, .linker_z_defs = linker_z_defs, .linker_z_origin = linker_z_origin, .linker_z_noexecstack = linker_z_noexecstack, |
