Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linker flag and LLD support. #2271

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
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.
29 changes: 29 additions & 0 deletions website/docs/linker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Specifies the linker.

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

### Parameters ###

`value` string, one of:

* `Default` - uses the toolset platform default linker.
* `LLD` - uses LLVM's LLD linker (supported on `gcc` and `clang` toolsets).

### Applies To ###

The `config` scope.

### 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