[U-Boot] [PATCH v4 1/2] tools, config.mk: add binutils-version

Modeled after gcc-version, add function to get binutils version.
Signed-off-by: Allen Martin amartin@nvidia.com --- config.mk | 1 + tools/binutils-version.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100755 tools/binutils-version.sh
diff --git a/config.mk b/config.mk index 3dcea6a..919b77d 100644 --- a/config.mk +++ b/config.mk @@ -128,6 +128,7 @@ endif # cc-version # Usage gcc-ver := $(call cc-version) cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC)) +binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh $(AS))
# # Include the make variables (CC, etc...) diff --git a/tools/binutils-version.sh b/tools/binutils-version.sh new file mode 100755 index 0000000..d4d9eb4 --- /dev/null +++ b/tools/binutils-version.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# binutils-version [-p] gas-command +# +# Prints the binutils version of `gas-command' in a canonical 4-digit form +# such as `0222' for binutils 2.22 +# + +gas="$*" + +if [ ${#gas} -eq 0 ]; then + echo "Error: No assembler specified." + printf "Usage:\n\t$0 <gas-command>\n" + exit 1 +fi + +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" $MAJOR $MINOR

Disable sibling call optimization based on binutils version. This is to work around a bug in the assember in binutils versions < 2.22. Branches to weak symbols can be incorrectly optimized in thumb mode to a short branch (b.n instruction) that won't reach when the symbol gets preempted.
http://sourceware.org/bugzilla/show_bug.cgi?id=12532
Signed-off-by: Allen Martin amartin@nvidia.com --- changes for v4: -removed warning print changes for v3: -split shell line to improve readability changes for v2: -changed GAS_BUG_12532 from yes/no to y/n to be consistent -added additional warning about code size increase --- arch/arm/config.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 3f4453a..24b9d7c 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -87,3 +87,21 @@ endif ifndef CONFIG_NAND_SPL LDFLAGS_u-boot += -pie endif + +# +# FIXME: binutils versions < 2.22 have a bug in the assembler where +# branches to weak symbols can be incorrectly optimized in thumb mode +# to a short branch (b.n instruction) that won't reach when the symbol +# gets preempted +# +# http://sourceware.org/bugzilla/show_bug.cgi?id=12532 +# +ifeq ($(CONFIG_SYS_THUMB_BUILD),y) +ifeq ($(GAS_BUG_12532),) +export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \ + then echo y; else echo n; fi) +endif +ifeq ($(GAS_BUG_12532),y) +PLATFORM_RELFLAGS += -fno-optimize-sibling-calls +endif +endif

Hi Allen,
On Wed, 18 Jul 2012 16:45:53 -0700, Allen Martin amartin@nvidia.com wrote:
Disable sibling call optimization based on binutils version. This is to work around a bug in the assember in binutils versions < 2.22. Branches to weak symbols can be incorrectly optimized in thumb mode to a short branch (b.n instruction) that won't reach when the symbol gets preempted.
http://sourceware.org/bugzilla/show_bug.cgi?id=12532
Signed-off-by: Allen Martin amartin@nvidia.com
changes for v4: -removed warning print changes for v3: -split shell line to improve readability changes for v2: -changed GAS_BUG_12532 from yes/no to y/n to be consistent
-added additional warning about code size increase
arch/arm/config.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 3f4453a..24b9d7c 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -87,3 +87,21 @@ endif ifndef CONFIG_NAND_SPL LDFLAGS_u-boot += -pie endif
+# +# FIXME: binutils versions < 2.22 have a bug in the assembler where +# branches to weak symbols can be incorrectly optimized in thumb mode +# to a short branch (b.n instruction) that won't reach when the symbol +# gets preempted +# +# http://sourceware.org/bugzilla/show_bug.cgi?id=12532 +# +ifeq ($(CONFIG_SYS_THUMB_BUILD),y) +ifeq ($(GAS_BUG_12532),) +export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \
- then echo y; else echo n; fi)
+endif +ifeq ($(GAS_BUG_12532),y) +PLATFORM_RELFLAGS += -fno-optimize-sibling-calls +endif +endif
Can previous reviewers ack or test this? I would like to have it in the ARM master branch in time for 12.07.
Amicalement,

On 07/18/2012 11:06 PM, Albert ARIBAUD wrote:
Hi Allen,
On Wed, 18 Jul 2012 16:45:53 -0700, Allen Martin amartin@nvidia.com wrote:
Disable sibling call optimization based on binutils version. This is to work around a bug in the assember in binutils versions < 2.22. Branches to weak symbols can be incorrectly optimized in thumb mode to a short branch (b.n instruction) that won't reach when the symbol gets preempted.
http://sourceware.org/bugzilla/show_bug.cgi?id=12532
Signed-off-by: Allen Martin amartin@nvidia.com
changes for v4: -removed warning print changes for v3: -split shell line to improve readability changes for v2: -changed GAS_BUG_12532 from yes/no to y/n to be consistent
-added additional warning about code size increase
arch/arm/config.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 3f4453a..24b9d7c 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -87,3 +87,21 @@ endif ifndef CONFIG_NAND_SPL LDFLAGS_u-boot += -pie endif
+# +# FIXME: binutils versions < 2.22 have a bug in the assembler where +# branches to weak symbols can be incorrectly optimized in thumb mode +# to a short branch (b.n instruction) that won't reach when the symbol +# gets preempted +# +# http://sourceware.org/bugzilla/show_bug.cgi?id=12532 +# +ifeq ($(CONFIG_SYS_THUMB_BUILD),y) +ifeq ($(GAS_BUG_12532),) +export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \
- then echo y; else echo n; fi)
+endif +ifeq ($(GAS_BUG_12532),y) +PLATFORM_RELFLAGS += -fno-optimize-sibling-calls +endif +endif
Can previous reviewers ack or test this? I would like to have it in the ARM master branch in time for 12.07.
Acked-by: Tom Rini trini@ti.com

On Thu, Jul 19, 2012 at 08:08:31AM -0700, Tom Rini wrote:
On 07/18/2012 11:06 PM, Albert ARIBAUD wrote:
Hi Allen,
On Wed, 18 Jul 2012 16:45:53 -0700, Allen Martin amartin@nvidia.com wrote:
Disable sibling call optimization based on binutils version. This is to work around a bug in the assember in binutils versions < 2.22. Branches to weak symbols can be incorrectly optimized in thumb mode to a short branch (b.n instruction) that won't reach when the symbol gets preempted.
http://sourceware.org/bugzilla/show_bug.cgi?id=12532
Signed-off-by: Allen Martin amartin@nvidia.com
Can previous reviewers ack or test this? I would like to have it in the ARM master branch in time for 12.07.
Acked-by: Tom Rini trini@ti.com
Hi Albert, just checking on the status of applying this to u-boot-arm. I have a patch series to enable thumb for tegra that needs this. I'll probably just keep a copy of this in that series until it goes in.
thanks, -Allen

Hi Allen,
On Wed, 18 Jul 2012 16:45:53 -0700, Allen Martin amartin@nvidia.com wrote:
Disable sibling call optimization based on binutils version. This is to work around a bug in the assember in binutils versions < 2.22. Branches to weak symbols can be incorrectly optimized in thumb mode to a short branch (b.n instruction) that won't reach when the symbol gets preempted.
http://sourceware.org/bugzilla/show_bug.cgi?id=12532
Signed-off-by: Allen Martin amartin@nvidia.com
changes for v4: -removed warning print changes for v3: -split shell line to improve readability changes for v2: -changed GAS_BUG_12532 from yes/no to y/n to be consistent
-added additional warning about code size increase
arch/arm/config.mk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 3f4453a..24b9d7c 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -87,3 +87,21 @@ endif ifndef CONFIG_NAND_SPL LDFLAGS_u-boot += -pie endif
+# +# FIXME: binutils versions < 2.22 have a bug in the assembler where +# branches to weak symbols can be incorrectly optimized in thumb mode +# to a short branch (b.n instruction) that won't reach when the symbol +# gets preempted +# +# http://sourceware.org/bugzilla/show_bug.cgi?id=12532 +# +ifeq ($(CONFIG_SYS_THUMB_BUILD),y) +ifeq ($(GAS_BUG_12532),) +export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \
- then echo y; else echo n; fi)
+endif +ifeq ($(GAS_BUG_12532),y) +PLATFORM_RELFLAGS += -fno-optimize-sibling-calls +endif +endif
Applied to u-boot-arm/master, thanks!
Amicalement,

On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
+printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }' -mike

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
- -- Tom

On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
+printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }' -mike

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 07/19/2012 08:21 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
And still over 80 chars before we assign it to a variable. I could get it to 77 chars with all whitespace removed.
- -- Tom

On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
On 07/19/2012 08:21 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
+printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
And still over 80 chars before we assign it to a variable. I could get it to 77 chars with all whitespace removed.
which is why i unrolled it to make it readable. i don't know what metrics you're using here, but i don't think the awk version is "longer" by really any of them. -mike

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 07/19/2012 09:43 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
On 07/19/2012 08:21 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
And still over 80 chars before we assign it to a variable. I could get it to 77 chars with all whitespace removed.
which is why i unrolled it to make it readable. i don't know what metrics you're using here, but i don't think the awk version is "longer" by really any of them.
The metric of 'wc -c' and "what fits in a single line, unwrapped on an 80x24 terminal." awk is great and awesome, don't get me wrong, but it's not doing the job as compactly as the original.
- -- Tom

On Thursday 19 July 2012 12:54:37 Tom Rini wrote:
On 07/19/2012 09:43 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
On 07/19/2012 08:21 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote:
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote: > +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | > cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk > '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" > $MAJOR $MINOR
can be replaced with a single awk script:
$gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
And still over 80 chars before we assign it to a variable. I could get it to 77 chars with all whitespace removed.
which is why i unrolled it to make it readable. i don't know what metrics you're using here, but i don't think the awk version is "longer" by really any of them.
The metric of 'wc -c' and "what fits in a single line, unwrapped on an 80x24 terminal." awk is great and awesome, don't get me wrong, but it's not doing the job as compactly as the original.
obviously i disagree. i find the awk version "better" in just about every way. maybe someone else will jump in with their favorite bike. -mike

On Wed, Aug 01, 2012 at 03:31:37PM -0700, Mike Frysinger wrote:
On Thursday 19 July 2012 12:54:37 Tom Rini wrote:
On 07/19/2012 09:43 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
On 07/19/2012 08:21 AM, Mike Frysinger wrote:
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
On 07/18/2012 08:11 PM, Mike Frysinger wrote: > On Wednesday 18 July 2012 19:45:52 Allen Martin wrote: >> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | >> cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk >> '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\n" >> $MAJOR $MINOR > > can be replaced with a single awk script: > > $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF > printf "%02d%02d\n", $1, $2 exit }'
That looks much longer and we call this once so a few execs is noise.
here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
And still over 80 chars before we assign it to a variable. I could get it to 77 chars with all whitespace removed.
which is why i unrolled it to make it readable. i don't know what metrics you're using here, but i don't think the awk version is "longer" by really any of them.
The metric of 'wc -c' and "what fits in a single line, unwrapped on an 80x24 terminal." awk is great and awesome, don't get me wrong, but it's not doing the job as compactly as the original.
obviously i disagree. i find the awk version "better" in just about every way. maybe someone else will jump in with their favorite bike.
As the original author I don't really care either way, I only care about working around the assembler bug so I can turn on thumb for tegra. But maybe I'll rewrite it in prolog just to mess with you guys :^)
-Allen

Hi Allen,
On Thu, Aug 2, 2012 at 8:46 AM, Allen Martin amartin@nvidia.com wrote:
[snip]
As the original author I don't really care either way, I only care about working around the assembler bug so I can turn on thumb for tegra. But maybe I'll rewrite it in prolog just to mess with you guys :^)
Honestly, I prefer the original version - It clearly shows what the code is doing. I'm not an awk god, and I find it really difficult to figure out what half of the fancy scripts littered about the Makefiles actually do. If it doesn't impact on performance, I prefer clarity (to non awk god-like creatures) the compactness.
Just my $0.02 worth
Regards,
Graeme

On Wed, Aug 01, 2012 at 04:01:41PM -0700, Mike Frysinger wrote:
On Wednesday 01 August 2012 18:46:18 Allen Martin wrote:
But maybe I'll rewrite it in prolog just to mess with you guys
i'd ack it if it were written in bf -mike
Challenge accepted
#!/bin/sh # # binutils-version [-p] gas-command # # Prints the binutils version of `gas-command' in a canonical 4-digit #form # such as `0222' for binutils 2.22 #
gas="$*"
if [ ${#gas} -eq 0 ]; then echo "Error: No assembler specified." printf "Usage:\n\t$0 <gas-command>\n" exit 1 fi
tmp=$(mktemp) echo '>>++++[<++++++++>-]>>+++++[>+++++++++<-]>+>,[>>++++[<++++++++>-]>>+++++[>\ +++++++++<-]>+>,]<<<<<<[<<<<<<]>>>>>>[<[<+>-]>[<<-<+>>>-]<<<[>>>+<<<-]>[>+<[-]]\
>>]<<<<<<[<<<<<<]>>>>>[>>>>>>]><<<<<<<<<<<<[-]<[-]++++++[>++++++++<-]>.>>\
.>>>>>>>>>>>>.>>>>>>.' > $tmp
$gas --version | bf -n $tmp rm $tmp
-Allen

Dear Allen Martin,
In message 20120802171230.GC7791@nvidia.com you wrote:
Challenge accepted
...
tmp=$(mktemp) echo '>>++++[<++++++++>-]>>+++++[>+++++++++<-]>+>,[>>++++[<++++++++>-]>>+++++[>\ +++++++++<-]>+>,]<<<<<<[<<<<<<]>>>>>>[<[<+>-]>[<<-<+>>>-]<<<[>>>+<<<-]>[>+<[-]]\
>>>]<<<<<<[<<<<<<]>>>>>[>>>>>>]><<<<<<<<<<<<[-]<[-]++++++[>++++++++<-]>.>>\
.>>>>>>>>>>>>.>>>>>>.' > $tmp
Thanks. Registered as entry # 1 for the IOUCC.
Best regards,
Wolfgang Denk
participants (6)
-
Albert ARIBAUD
-
Allen Martin
-
Graeme Russ
-
Mike Frysinger
-
Tom Rini
-
Wolfgang Denk