stripping lto flags doesn't work as expected
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dh-golang (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
dpkg (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
In dh-golang, we use dpkg's C flags as Go's CGO flags. When dpkg's LTO feature is enabled, the LTO C flags may pass to CGO as well. But Go's linker doesn't support LTO. So in dh-golang, we implemented a workround to strip LTO flag[1].
```
$bf->strip($flag, "-ffat-lto-objects -flto=auto");
```
This works well in Debian, but it turns out not robust for Ubuntu.
In Ubuntu, we get such C flags:
```
$ dpkg-buildflags --get CFLAGS
-g -O2 -ffile-
```
It has two duplicated `-flto=auto -ffat-lto-objects`. So dh-golang's code doesn't handle it robustly. One `-flto=auto -ffat-lto-objects` set is still passed to CGO. This causes link error.
description: | updated |
tags: | added: fr-3163 |
Changed in dpkg (Ubuntu): | |
status: | New → Fix Committed |
Changed in dpkg (Ubuntu): | |
status: | Fix Committed → Fix Released |
$bf->strip first split its input (here is `-ffat-lto-objects -flto=auto`), then use for loop to strip every flag.
```
$self- >{flags} ->{$flag} =~ s/(^|\s+ )\Q$tostrip\ E(\s+|$ )/ /g;
my ($self, $flag, $value, $src, $maint) = @_;
foreach my $tostrip (split(/\s+/, $value)) {
next unless length $tostrip;
}
```
It does use `g` flag in regex, (maybe want to strip all duplicated flag?)
In first loop, for `-ffat- lto-objects` , it does strip two `-ffat- lto-objects` . Then the flag becomes `-flto=auto -flto=auto`.
Then in second loop, it stops working. Because there's only one space between two `-flto=auto`. However the regex expects space before and after one token. So it only strips one `-flto=auto`.
See https:/ /regex101. com/r/AgDMzv/ 1 for regex debug.