Skip to content

Commit

Permalink
Add linker flag and LLD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Sep 28, 2024
1 parent 6d3c962 commit 4d16486
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,16 @@
}
}

api.register {
name = "linker",
scope = "config",
kind = "string",
allowed = {
"Default",
"LLD",
}
}

api.register {
name = "locale",
scope = "config",
Expand Down
1 change: 1 addition & 0 deletions src/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
if cfg.system == p.WINDOWS then return "-mwindows" end
end,
},
linker = gcc.ldflags.linker,
sanitize = {
Address = "-fsanitize=address",
},
Expand Down
4 changes: 4 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@
if cfg.system == p.WINDOWS then return "-mwindows" end
end,
},
linker = {
Default = "",
LLD = "-fuse-ld=lld"
},
sanitize = {
Address = "-fsanitize=address",
},
Expand Down
10 changes: 10 additions & 0 deletions tests/tools/test_clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
test.excludes("-fopenmp", clang.getcflags(cfg))
end

--
-- Check handling of linker flag.
--

function suite.ldflags_linker_lld()
linker "LLD"
prepare()
test.contains("-fuse-ld=lld", clang.getldflags(cfg))
end

--
-- Check the translation of CXXFLAGS.
--
Expand Down
11 changes: 11 additions & 0 deletions tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,17 @@
end


--
-- Check handling of linker flag.
--

function suite.ldflags_linker_lld()
linker "LLD"
prepare()
test.contains("-fuse-ld=lld", gcc.getldflags(cfg))
end


--
-- Check handling of link time optimization flag.
--
Expand Down
4 changes: 4 additions & 0 deletions website/docs/Linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ If you need to discover the location of a library, use the [`os.findlib`](os.fin
```lua
libdirs { os.findlib("X11") }
```

### Linker

The linker defaults to the specified toolset default linker, but can be changed with the [`linker`](linker.md) flag.
28 changes: 28 additions & 0 deletions website/docs/linker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Specifies the linker.

```lua
linker("value")
```

### Parameters ###

`value` is a string value.

By default, `Default` and `LLD` are allowed, but toolsets or modules canprovide support for other linkers.

### Applies To ###

Project configurations.

### Availability ###

Premake 5.0 beta 3 or later.

### Examples ###

Sets `LLD` as the linker.

```lua
filter { "toolset:clang" }
linker { "LLD" }
```
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ module.exports = {
'largeaddressaware',
'libdirs',
'linkbuildoutputs',
'linker',
'linkgroups',
'linkoptions',
'links',
Expand Down

0 comments on commit 4d16486

Please sign in to comment.