Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/eld/Config/GeneralOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GeneralOptions {

typedef llvm::StringMap<uint64_t> AddressMapType;

enum class SeparateSegmentKind { None, Code };
enum class SeparateSegmentKind { None, Code, Loadable };

enum StripSymbolMode {
KeepAllSymbols,
Expand Down
3 changes: 2 additions & 1 deletion include/eld/Driver/GnuLinkerOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,8 @@ defm dash_z
"\t\t\t-z=text : Do not permit relocations in read-only segments (default)\n"
"\t\t\t-z=notext : Allow relocations in read-only segments\n"
"\t\t\t-z=separate-code : Create separate code segment\n"
"\t\t\t-z=no-separate-code : Do not create separate code segment\n">,
"\t\t\t-z=no-separate-code : Do not create separate code segment\n"
"\t\t\t-z=separate-loadable-segments : Create separate loadable segments\n">,
MetaVarName<"<extended-opts>">,
Group<grp_extendedopts>;
def no_align_segments : Flag<["--"], "no-align-segments">,
Expand Down
1 change: 1 addition & 0 deletions include/eld/Input/ZOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ZOption {
NoExecStack,
NoGnuStack,
SeparateCode,
SeparateLoadableSegments,
NoSeparateCode,
NoRelro,
Now,
Expand Down
7 changes: 5 additions & 2 deletions lib/Config/GeneralOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ bool GeneralOptions::addZOption(const ZOption &POption) {
case ZOption::NoGnuStack:
NoGnuStack = true;
break;
case eld::ZOption::SeparateCode:
case ZOption::SeparateCode:
setSeparateSegmentKind(SeparateSegmentKind::Code);
break;
case eld::ZOption::NoSeparateCode:
case ZOption::NoSeparateCode:
setSeparateSegmentKind(SeparateSegmentKind::None);
break;
case ZOption::SeparateLoadableSegments:
setSeparateSegmentKind(SeparateSegmentKind::Loadable);
break;
case ZOption::Global:
BGlobal = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions lib/LinkerWrapper/GnuLdDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ bool GnuLdDriver::processOptions(llvm::opt::InputArgList &Args) {
ZKind = eld::ZOption::SeparateCode;
else if (ZOpt == "noseparate-code")
ZKind = eld::ZOption::NoSeparateCode;
else if (ZOpt == "separate-loadable-segments")
ZKind = eld::ZOption::SeparateLoadableSegments;
else if (ZOpt == "execstack")
ZKind = eld::ZOption::ExecStack;
else if (ZOpt == "nodelete") {
Expand Down
2 changes: 2 additions & 0 deletions lib/Target/CreateProgramHeaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ bool GNULDBackend::createProgramHdrs() {
return true;
if (!ShouldSeparate)
return false;
if (SeparateKind == GeneralOptions::SeparateSegmentKind::Loadable)
return true;
if (!prevOut)
return false;
auto PrevSegIt = _segmentsForSection.find(prevOut);
Expand Down
5 changes: 2 additions & 3 deletions test/lld/ELF/separate-segments.s
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
# CODE-NEXT: LOAD 0x003000 0x0000000000003000 0x0000000000003000 0x000001 0x000001 R 0x1000
# CODE-NEXT: LOAD 0x003008 0x0000000000003008 0x0000000000003008 0x0000f1 0x0000f1 RW 0x1000

## TODO:
## -z separate-loadable-segments makes all segments separate.
# %link -pie --no-align-segments --rosegment %t.o -z separate-loadable-segments -o %t
# llvm-readelf -l %t | FileCheck --check-prefix=ALL %s
# RUN: %link -pie --no-align-segments --rosegment %t.o -z separate-loadable-segments -o %t
# RUN: llvm-readelf -l %t | FileCheck --check-prefix=ALL %s
# ALL: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000200 0x000200 R E 0x1000
# ALL-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000044 0x000044 R 0x1000
# ALL-NEXT: LOAD 0x002000 0x0000000000002000 0x0000000000002000 0x000001 0x000001 R E 0x1000
Expand Down
Loading