Skip to contentSkip to conversation

tools/resolve_btfids: Fix sections with wrong alignment

PATCH In review Jiri Olsa 8 participants 15 messages Aug 19, 2020 – Aug 20, 2020

Subsystems (3)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 tools/resolve_btfids: Fix sections with wrong alignment

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

  $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
  ...
  section(36) .comment, size 44, link 0, flags 30, type=1
  section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(38) .debug_info, size 129104957, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(40) .debug_line, size 7374522, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(41) .debug_frame, size 702463, link 0, flags 800, type=1
  section(42) .debug_str, size 1017571, link 0, flags 830, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(45) .symtab, size 2955888, link 46, flags 0, type=2
  section(46) .strtab, size 2613072, link 0, flags 0, type=3
  ...
  update ok for vmlinux

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

Fixes fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Cc Mark Wielaard <[email protected]>
Cc Nick Clifton <[email protected]>
---
 tools/bpf/resolve_btfids/main.c | 36 +++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/bpf/resolve_btfids/main.c +36 -0
index 4d9ecb975862..0def0bb1f783 100644
@@ -233,6 +233,39 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
 	return btf_id__add(root, id, false);
 }
 
+/*
+ * The data of compressed section should be aligned to 4
+ * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld
+ * sets sh_addralign to 1, which makes libelf fail with
+ * misaligned section error during the update:
+ *    FAILED elf_update(WRITE): invalid section alignment
+ *
+ * While waiting for ld fix, we fix the compressed sections
+ * sh_addralign value manualy.
+ */
+static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
+{
+	int expected = gelf_getclass(elf) == ELFCLASS32 ? 4 : 8;
+
+	if (!(sh->sh_flags & SHF_COMPRESSED))
+		return 0;
+
+	if (sh->sh_addralign == expected)
+		return 0;
+
+	pr_debug2(" - fixing wrong alignment sh_addralign %u, expected %u\n",
+		  sh->sh_addralign, expected);
+
+	sh->sh_addralign = expected;
+
+	if (gelf_update_shdr(scn, sh) == 0) {
+		printf("FAILED cannot update section header: %s\n",
+			elf_errmsg(-1));
+		return -1;
+	}
+	return 0;
+}
+
 static int elf_collect(struct object *obj)
 {
 	Elf_Scn *scn = NULL;
@@ -309,6 +342,9 @@ static int elf_collect(struct object *obj)
 			obj->efile.idlist_shndx = idx;
 			obj->efile.idlist_addr  = sh.sh_addr;
 		}
+
+		if (compressed_section_fix(elf, scn, &sh))
+			return -1;
 	}
 
 	return 0;
Signature · 1 line
2.25.4
#1 lore raw
Quoted 37 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

   $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
   ...
   section(36) .comment, size 44, link 0, flags 30, type=1
   section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(38) .debug_info, size 129104957, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(40) .debug_line, size 7374522, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(41) .debug_frame, size 702463, link 0, flags 800, type=1
   section(42) .debug_str, size 1017571, link 0, flags 830, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(45) .symtab, size 2955888, link 46, flags 0, type=2
   section(46) .strtab, size 2613072, link 0, flags 0, type=3
   ...
   update ok for vmlinux
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   elf_iamcu
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe
$

Do you know what is the issue here?

Quoted 65 lines
Fixes fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Cc Mark Wielaard <[email protected]>
Cc Nick Clifton <[email protected]>
---
  tools/bpf/resolve_btfids/main.c | 36 +++++++++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)
tools/bpf/resolve_btfids/main.c +36 -0
index 4d9ecb975862..0def0bb1f783 100644
@@ -233,6 +233,39 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
  	return btf_id__add(root, id, false);
  }
 
+/*
+ * The data of compressed section should be aligned to 4
+ * (for 32bit) or 8 (for 64 bit) bytes. The binutils ld
+ * sets sh_addralign to 1, which makes libelf fail with
+ * misaligned section error during the update:
+ *    FAILED elf_update(WRITE): invalid section alignment
+ *
+ * While waiting for ld fix, we fix the compressed sections
+ * sh_addralign value manualy.
+ */
+static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
+{
+	int expected = gelf_getclass(elf) == ELFCLASS32 ? 4 : 8;
+
+	if (!(sh->sh_flags & SHF_COMPRESSED))
+		return 0;
+
+	if (sh->sh_addralign == expected)
+		return 0;
+
+	pr_debug2(" - fixing wrong alignment sh_addralign %u, expected %u\n",
+		  sh->sh_addralign, expected);
+
+	sh->sh_addralign = expected;
+
+	if (gelf_update_shdr(scn, sh) == 0) {
+		printf("FAILED cannot update section header: %s\n",
+			elf_errmsg(-1));
+		return -1;
+	}
+	return 0;
+}
+
  static int elf_collect(struct object *obj)
  {
  	Elf_Scn *scn = NULL;
@@ -309,6 +342,9 @@ static int elf_collect(struct object *obj)
  			obj->efile.idlist_shndx = idx;
  			obj->efile.idlist_addr  = sh.sh_addr;
  		}
+
+		if (compressed_section_fix(elf, scn, &sh))
+			return -1;
  	}
 
  	return 0;
#2 lore raw
Quoted 40 lines · Yonghong Song
Quoted 37 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

   $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
   ...
   section(36) .comment, size 44, link 0, flags 30, type=1
   section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(38) .debug_info, size 129104957, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(40) .debug_line, size 7374522, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(41) .debug_frame, size 702463, link 0, flags 800, type=1
   section(42) .debug_str, size 1017571, link 0, flags 830, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(45) .symtab, size 2955888, link 46, flags 0, type=2
   section(46) .strtab, size 2613072, link 0, flags 0, type=3
   ...
   update ok for vmlinux
Quoted 4 lines
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

correct

Quoted 43 lines

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   elf_iamcu
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe
$
Quoted 1 line

Do you know what is the issue here?

mine's: GNU ld version 2.32-31.fc31

there's version info in commit:
10e68b02c861 Makefile: support compressed debug info

Compress the debug information using zlib. Requires GCC 5.0+ or Clang 5.0+, binutils 2.26+, and zlib.

cc-ing Nick Desaulniers, author of that patch.. any idea about the error above?

thanks,
jirka

#3 lore raw
Quoted 8 lines · Jiri Olsa
Quoted 6 lines · Yonghong Song
Quoted 3 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Is there a bug filed against GNU ld? Link?

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Adding warning in -vv mode when the fix is triggered:

   $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
   ...
   section(36) .comment, size 44, link 0, flags 30, type=1
   section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(38) .debug_info, size 129104957, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(40) .debug_line, size 7374522, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(41) .debug_frame, size 702463, link 0, flags 800, type=1
   section(42) .debug_str, size 1017571, link 0, flags 830, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(45) .symtab, size 2955888, link 46, flags 0, type=2
   section(46) .strtab, size 2613072, link 0, flags 0, type=3
   ...
   update ok for vmlinux
Quoted 48 lines
Quoted 4 lines
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

correct

Quoted 41 lines

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   elf_iamcu
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe

According to Documentation/process/changes.rst, the minimum supported version of GNU binutils for the kernels is 2.23. Can you upgrade to that and confirm that you still observe the issue? I don't want to spend time chasing bugs in old, unsupported versions of GNU binutils, especially as Jiri notes, 2.26 is required for CONFIG_DEBUG_INFO_COMPRESSED. We can always strengthen the Kconfig check for it. Otherwise, I'm not familiar with the observed error message.

Quoted 17 lines
Quoted 3 lines

$

Do you know what is the issue here?

mine's: GNU ld version 2.32-31.fc31

there's version info in commit:
10e68b02c861 Makefile: support compressed debug info

Compress the debug information using zlib. Requires GCC 5.0+ or Clang 5.0+, binutils 2.26+, and zlib.

cc-ing Nick Desaulniers, author of that patch.. any idea about the error above?

thanks,
jirka

Signature · 2 lines
Thanks,
~Nick Desaulniers
#4 lore raw
Quoted 95 lines · Nick Desaulniers
Quoted 8 lines · Jiri Olsa
Quoted 6 lines · Yonghong Song
Quoted 3 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Is there a bug filed against GNU ld? Link?

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Adding warning in -vv mode when the fix is triggered:

    $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
    ...
    section(36) .comment, size 44, link 0, flags 30, type=1
    section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(38) .debug_info, size 129104957, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(40) .debug_line, size 7374522, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(41) .debug_frame, size 702463, link 0, flags 800, type=1
    section(42) .debug_str, size 1017571, link 0, flags 830, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(45) .symtab, size 2955888, link 46, flags 0, type=2
    section(46) .strtab, size 2613072, link 0, flags 0, type=3
    ...
    update ok for vmlinux
Quoted 48 lines
Quoted 4 lines
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

correct

Quoted 41 lines

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
   Supported emulations:
    elf_x86_64
    elf32_x86_64
    elf_i386
    elf_iamcu
    i386linux
    elf_l1om
    elf_k1om
    i386pep
    i386pe
Quoted 8 lines

According to Documentation/process/changes.rst, the minimum supported version of GNU binutils for the kernels is 2.23. Can you upgrade to that and confirm that you still observe the issue? I don't want to spend time chasing bugs in old, unsupported versions of GNU binutils, especially as Jiri notes, 2.26 is required for CONFIG_DEBUG_INFO_COMPRESSED. We can always strengthen the Kconfig check for it. Otherwise, I'm not familiar with the observed error message.

I built a "ld" with latest binutils-gdb repo and I can reproduced the issue. Indeed applying the patch here fixed the issue. So I think there is no need to investigate since upstream exhibits the exact issue described here.

Quoted 20 lines
Quoted 18 lines
Quoted 4 lines

$

Do you know what is the issue here?

mine's: GNU ld version 2.32-31.fc31

there's version info in commit:
10e68b02c861 Makefile: support compressed debug info

Compress the debug information using zlib. Requires GCC 5.0+ or Clang 5.0+, binutils 2.26+, and zlib.

cc-ing Nick Desaulniers, author of that patch.. any idea about the error above?

thanks,
jirka

#5 lore raw
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
   section(36) .comment, size 44, link 0, flags 30, type=1
   section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(38) .debug_info, size 129104957, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(40) .debug_line, size 7374522, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(41) .debug_frame, size 702463, link 0, flags 800, type=1
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
   section(42) .debug_str, size 1017571, link 0, flags 830, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(45) .symtab, size 2955888, link 46, flags 0, type=2
   section(46) .strtab, size 2613072, link 0, flags 0, type=3

I think this is resolve_btfids's bug. GNU ld and LLD are innocent. These .debug_* sections work fine if their sh_addralign is 1. When the section flag SHF_COMPRESSED is set, the meaningful alignment is Elf64_Chdr::ch_addralign, after the header is uncompressed.

Quoted 133 lines · Yonghong Song
Quoted 95 lines · Nick Desaulniers
Quoted 8 lines · Jiri Olsa
Quoted 6 lines · Yonghong Song
Quoted 3 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Is there a bug filed against GNU ld? Link?

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Adding warning in -vv mode when the fix is triggered:

    $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
    ...
    section(36) .comment, size 44, link 0, flags 30, type=1
    section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(38) .debug_info, size 129104957, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(40) .debug_line, size 7374522, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(41) .debug_frame, size 702463, link 0, flags 800, type=1
    section(42) .debug_str, size 1017571, link 0, flags 830, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(45) .symtab, size 2955888, link 46, flags 0, type=2
    section(46) .strtab, size 2613072, link 0, flags 0, type=3
    ...
    update ok for vmlinux
Quoted 48 lines
Quoted 4 lines
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

correct

Quoted 41 lines

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
   Supported emulations:
    elf_x86_64
    elf32_x86_64
    elf_i386
    elf_iamcu
    i386linux
    elf_l1om
    elf_k1om
    i386pep
    i386pe
Quoted 8 lines

According to Documentation/process/changes.rst, the minimum supported version of GNU binutils for the kernels is 2.23. Can you upgrade to that and confirm that you still observe the issue? I don't want to spend time chasing bugs in old, unsupported versions of GNU binutils, especially as Jiri notes, 2.26 is required for CONFIG_DEBUG_INFO_COMPRESSED. We can always strengthen the Kconfig check for it. Otherwise, I'm not familiar with the observed error message.

I built a "ld" with latest binutils-gdb repo and I can reproduced the issue. Indeed applying the patch here fixed the issue. So I think there is no need to investigate since upstream exhibits the exact issue described here.

Quoted 20 lines
Quoted 18 lines
Quoted 4 lines

$

Do you know what is the issue here?

mine's: GNU ld version 2.32-31.fc31

there's version info in commit:
10e68b02c861 Makefile: support compressed debug info

Compress the debug information using zlib. Requires GCC 5.0+ or Clang 5.0+, binutils 2.26+, and zlib.

cc-ing Nick Desaulniers, author of that patch.. any idea about the error above?

thanks,
jirka

Signature · 1 line
宋方睿
#6 lore raw
Quoted 19 lines · Fāng-ruì Sòng
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
    section(36) .comment, size 44, link 0, flags 30, type=1
    section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(38) .debug_info, size 129104957, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(40) .debug_line, size 7374522, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(41) .debug_frame, size 702463, link 0, flags 800, type=1
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
    section(42) .debug_str, size 1017571, link 0, flags 830, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(45) .symtab, size 2955888, link 46, flags 0, type=2
    section(46) .strtab, size 2613072, link 0, flags 0, type=3
Quoted 24 lines

I think this is resolve_btfids's bug. GNU ld and LLD are innocent. These .debug_* sections work fine if their sh_addralign is 1. When the section flag SHF_COMPRESSED is set, the meaningful alignment is Elf64_Chdr::ch_addralign, after the header is uncompressed.

Quoted 18 lines · Yonghong Song
Quoted 14 lines · Nick Desaulniers
Quoted 13 lines · Jiri Olsa
Quoted 11 lines · Yonghong Song
Quoted 8 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

Jiri,

Since Fangrui mentioned this is not a ld/lld bug, then changing alighment from 1 to 4 might have some adverse effect for the binary, I guess.

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

Yonghong

Quoted 118 lines
Quoted 115 lines
Quoted 81 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Is there a bug filed against GNU ld? Link?

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Adding warning in -vv mode when the fix is triggered:

     $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
     ...
     section(36) .comment, size 44, link 0, flags 30, type=1
     section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 16, expected 8
     section(38) .debug_info, size 129104957, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 1, expected 8
     section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 1, expected 8
     section(40) .debug_line, size 7374522, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 1, expected 8
     section(41) .debug_frame, size 702463, link 0, flags 800, type=1
     section(42) .debug_str, size 1017571, link 0, flags 830, type=1
      - fixing wrong alignment sh_addralign 1, expected 8
     section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 1, expected 8
     section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
      - fixing wrong alignment sh_addralign 16, expected 8
     section(45) .symtab, size 2955888, link 46, flags 0, type=2
     section(46) .strtab, size 2613072, link 0, flags 0, type=3
     ...
     update ok for vmlinux
Quoted 48 lines
Quoted 4 lines
Quoted 2 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

So CONFIG_DEBUG_INFO_COMPRESSED is required to reproduce the bug, right?

correct

Quoted 41 lines

I turned on CONFIG_DEBUG_INFO_COMPRESSED in my config and got a bunch of build failures.

ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info
ld: drivers/crypto/virtio/virtio_crypto_algs.o: unable to initialize decompress status for section .debug_info drivers/crypto/virtio/virtio_crypto_algs.o: file not recognized: File format not recognized

ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
ld: net/llc/llc_core.o: unable to initialize decompress status for section .debug_info
net/llc/llc_core.o: file not recognized: File format not recognized

...

The 'ld' in my system:

$ ld -V
GNU ld version 2.30-74.el8
    Supported emulations:
     elf_x86_64
     elf32_x86_64
     elf_i386
     elf_iamcu
     i386linux
     elf_l1om
     elf_k1om
     i386pep
     i386pe
Quoted 8 lines

According to Documentation/process/changes.rst, the minimum supported version of GNU binutils for the kernels is 2.23. Can you upgrade to that and confirm that you still observe the issue? I don't want to spend time chasing bugs in old, unsupported versions of GNU binutils, especially as Jiri notes, 2.26 is required for CONFIG_DEBUG_INFO_COMPRESSED. We can always strengthen the Kconfig check for it. Otherwise, I'm not familiar with the observed error message.

I built a "ld" with latest binutils-gdb repo and I can reproduced the issue. Indeed applying the patch here fixed the issue. So I think there is no need to investigate since upstream exhibits the exact issue described here.

Quoted 20 lines
Quoted 18 lines
Quoted 4 lines

$

Do you know what is the issue here?

mine's: GNU ld version 2.32-31.fc31

there's version info in commit:
10e68b02c861 Makefile: support compressed debug info

Compress the debug information using zlib. Requires GCC 5.0+ or Clang 5.0+, binutils 2.26+, and zlib.

cc-ing Nick Desaulniers, author of that patch.. any idea about the error above?

thanks,
jirka

#7 lore raw

Hi,

Quoted 8 lines · Yonghong Song
Quoted 7 lines · Fāng-ruì Sòng
Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this is resolve_btfids's bug. GNU ld and LLD are innocent. These .debug_* sections work fine if their sh_addralign is 1. When the section flag SHF_COMPRESSED is set, the meaningful alignment
is Elf64_Chdr::ch_addralign, after the header is uncompressed.

Quoted 4 lines
Quoted 1 line · Yonghong Song

Since Fangrui mentioned this is not a ld/lld bug, then changing alighment from 1 to 4 might have some adverse effect for the binary, I guess.

The bug isn't about a wrong ch_addralign, which seems to have been set correctly. But it is a bug about incorrectly setting the sh_addralign of the section. The sh_addralign indicates the alignment of the data in the section, which is the Elf32/64_Chdr plus compressed data, not the alignment of the uncompressed data. It helps the consumer make sure they lay out the data so that the ELF data structures can be read through their natural alignment.

In practice it often isn't a real issue, because consumers, including libelf, will correct the data alignment before usage anyway. But that doesn't mean it isn't a bug to set it wrongly.

Quoted 3 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

The issue is that elfutils libelf will not allow writing out the section when it notices the sh_addralign field is setup wrongly.

Cheers,

Mark

#8 lore raw
Quoted 28 lines · Mark Wielaard

Hi,

Quoted 8 lines · Yonghong Song
Quoted 7 lines · Fāng-ruì Sòng
Quoted 1 line
Quoted 1 line
Quoted 1 line

I think this is resolve_btfids's bug. GNU ld and LLD are innocent. These .debug_* sections work fine if their sh_addralign is 1. When the section flag SHF_COMPRESSED is set, the meaningful alignment
is Elf64_Chdr::ch_addralign, after the header is uncompressed.

Quoted 4 lines
Quoted 1 line · Yonghong Song

Since Fangrui mentioned this is not a ld/lld bug, then changing alighment from 1 to 4 might have some adverse effect for the binary, I guess.

The bug isn't about a wrong ch_addralign, which seems to have been set correctly. But it is a bug about incorrectly setting the sh_addralign of the section. The sh_addralign indicates the alignment of the data in the section, which is the Elf32/64_Chdr plus compressed data, not the alignment of the uncompressed data. It helps the consumer make sure they lay out the data so that the ELF data structures can be read through their natural alignment.

In practice it often isn't a real issue, because consumers, including libelf, will correct the data alignment before usage anyway. But that doesn't mean it isn't a bug to set it wrongly.

Quoted 6 lines
Quoted 3 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

The issue is that elfutils libelf will not allow writing out the section when it notices the sh_addralign field is setup wrongly.

Maybe resolve_btfids can temporarily change sh_addralign to 4/8 before elf manipulation (elf_write) to make libelf happy. After all elf_write is done, change back to whatever the original value (1). Does this work?

Quoted 5 lines

Cheers,

Mark

#9 lore raw

Hi

Quoted 5 lines · Yonghong Song
Quoted 5 lines
Quoted 4 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

Quoted 7 lines
Quoted 2 lines

The issue is that elfutils libelf will not allow writing out the section when it notices the sh_addralign field is setup wrongly.

Maybe resolve_btfids can temporarily change sh_addralign to 4/8 before elf manipulation (elf_write) to make libelf happy. After all elf_write is done, change back to whatever the original value (1). Does this work?

Unfortunately no, because there is no elf_write, elf_update is how you write out the ELF image to disc.

Since the code is using ELF_F_LAYOUT this will not change the actual layout of the ELF image if that is what you are worried about.

And the workaround to set sh_addralign correctly before calling elf_update is precisely what the fix in elfutils libelf will do itself in the next release. Also binutils ld has been fixed to setup sh_addralign to 4/8 as appropriate now (in git).

Cheers,

Mark

#10 lore raw
Quoted 19 lines · Mark Wielaard

Hi

Quoted 5 lines · Yonghong Song
Quoted 5 lines
Quoted 4 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

Quoted 7 lines
Quoted 2 lines

The issue is that elfutils libelf will not allow writing out the section when it notices the sh_addralign field is setup wrongly.

Maybe resolve_btfids can temporarily change sh_addralign to 4/8 before elf manipulation (elf_write) to make libelf happy. After all elf_write is done, change back to whatever the original value (1). Does this work?

Unfortunately no, because there is no elf_write, elf_update is how you write out the ELF image to disc.

Quoted 7 lines

Since the code is using ELF_F_LAYOUT this will not change the actual layout of the ELF image if that is what you are worried about.

And the workaround to set sh_addralign correctly before calling elf_update is precisely what the fix in elfutils libelf will do itself in the next release. Also binutils ld has been fixed to setup sh_addralign to 4/8 as appropriate now (in git).

Sounds good then.
Thanks for fixing the issue in upstream, both libelf and binutils!

Quoted 5 lines

Cheers,

Mark

#11 lore raw
Quoted 26 lines · Yonghong Song
Quoted 22 lines · Mark Wielaard

Hi

Quoted 5 lines · Yonghong Song
Quoted 5 lines
Quoted 4 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read these sections. This way, no need to change their alignment either.

Quoted 7 lines
Quoted 2 lines

The issue is that elfutils libelf will not allow writing out the section when it notices the sh_addralign field is setup wrongly.

Maybe resolve_btfids can temporarily change sh_addralign to 4/8 before elf manipulation (elf_write) to make libelf happy. After all elf_write is done, change back to whatever the original value (1). Does this work?

Unfortunately no, because there is no elf_write, elf_update is how you write out the ELF image to disc.

Since the code is using ELF_F_LAYOUT this will not change the actual layout of the ELF image if that is what you are worried about.

Quoted 7 lines
Quoted 4 lines

And the workaround to set sh_addralign correctly before calling elf_update is precisely what the fix in elfutils libelf will do itself in the next release. Also binutils ld has been fixed to setup sh_addralign to 4/8 as appropriate now (in git).

Sounds good then.
Thanks for fixing the issue in upstream, both libelf and binutils!

In the meantime I've applied Jiri's workaround to bpf tree. Thanks!

#12 lore raw
In reply to Yonghong Song
Quoted 45 lines · Yonghong Song
Quoted 42 lines · Fāng-ruì Sòng
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
    section(36) .comment, size 44, link 0, flags 30, type=1
    section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(38) .debug_info, size 129104957, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(40) .debug_line, size 7374522, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(41) .debug_frame, size 702463, link 0, flags 800, type=1
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
    section(42) .debug_str, size 1017571, link 0, flags 830, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 1, expected 8
    section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
     - fixing wrong alignment sh_addralign 16, expected 8
    section(45) .symtab, size 2955888, link 46, flags 0, type=2
    section(46) .strtab, size 2613072, link 0, flags 0, type=3

I think this is resolve_btfids's bug. GNU ld and LLD are innocent. These .debug_* sections work fine if their sh_addralign is 1. When the section flag SHF_COMPRESSED is set, the meaningful alignment is Elf64_Chdr::ch_addralign, after the header is uncompressed.

Quoted 17 lines · Yonghong Song
Quoted 13 lines · Nick Desaulniers
Quoted 12 lines · Jiri Olsa
Quoted 10 lines · Yonghong Song
Quoted 7 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

FAILED elf_update(WRITE): invalid section alignment

Jiri,

Since Fangrui mentioned this is not a ld/lld bug, then changing alighment from 1 to 4 might have some adverse effect for the binary, I guess.

not sure about that.. Mark? ;-)

Quoted 4 lines

Do you think we could skip these .debug_* sections somehow in elf parsing in resolve_btfids? resolve_btfids does not need to read
these sections. This way, no need to change their alignment either.

I'm don't think libelf interface allows for that, will check

jirka

Acked-by on v1 1/1
#13 lore raw
In reply to Jiri Olsa
Quoted 28 lines · On Wed, 19 Aug 2020 11:23:42 +0200 Jiri Olsa <[email protected]> wrote:

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

  $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
  ...
  section(36) .comment, size 44, link 0, flags 30, type=1
  section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(38) .debug_info, size 129104957, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(40) .debug_line, size 7374522, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(41) .debug_frame, size 702463, link 0, flags 800, type=1
  section(42) .debug_str, size 1017571, link 0, flags 830, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
Quoted 8 lines
  section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 1, expected 8
  section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
   - fixing wrong alignment sh_addralign 16, expected 8
  section(45) .symtab, size 2955888, link 46, flags 0, type=2
  section(46) .strtab, size 2613072, link 0, flags 0, type=3
  ...
  update ok for vmlinux

I also works for me:

[...]
section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 16, expected 8
section(38) .debug_info, size 129098181, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 1, expected 8
section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 1, expected 8
section(40) .debug_line, size 7374522, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 1, expected 8
section(41) .debug_frame, size 702463, link 0, flags 800, type=1 section(42) .debug_str, size 1017606, link 0, flags 830, type=1
- fixing wrong alignment sh_addralign 1, expected 8
section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 1, expected 8
section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
- fixing wrong alignment sh_addralign 16, expected 8
section(45) .symtab, size 2955888, link 46, flags 0, type=2 section(46) .strtab, size 2613072, link 0, flags 0, type=3 section(47) .shstrtab, size 525, link 0, flags 0, type=3 [...]
update ok for vmlinux.err.bak

Quoted 10 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

Fixes fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Cc Mark Wielaard <[email protected]>
Cc Nick Clifton <[email protected]>

---

Thanks for fixing this!

Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
Acked-by on v1 1/1
#14 lore raw
In reply to Jiri Olsa
Quoted 37 lines · Jiri Olsa

The data of compressed section should be aligned to 4 (for 32bit) or 8 (for 64 bit) bytes.

The binutils ld sets sh_addralign to 1, which makes libelf fail with misaligned section error during the update as reported by Jesper:

FAILED elf_update(WRITE): invalid section alignment

While waiting for ld fix, we can fix compressed sections sh_addralign value manually.

Adding warning in -vv mode when the fix is triggered:

   $ ./tools/bpf/resolve_btfids/resolve_btfids -vv vmlinux
   ...
   section(36) .comment, size 44, link 0, flags 30, type=1
   section(37) .debug_aranges, size 45684, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(38) .debug_info, size 129104957, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(39) .debug_abbrev, size 1152583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(40) .debug_line, size 7374522, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(41) .debug_frame, size 702463, link 0, flags 800, type=1
   section(42) .debug_str, size 1017571, link 0, flags 830, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(43) .debug_loc, size 3019453, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 1, expected 8
   section(44) .debug_ranges, size 1744583, link 0, flags 800, type=1
    - fixing wrong alignment sh_addralign 16, expected 8
   section(45) .symtab, size 2955888, link 46, flags 0, type=2
   section(46) .strtab, size 2613072, link 0, flags 0, type=3
   ...
   update ok for vmlinux
Quoted 8 lines

Another workaround is to disable compressed debug info data CONFIG_DEBUG_INFO_COMPRESSED kernel option.

Fixes fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Cc Mark Wielaard <[email protected]>
Cc Nick Clifton <[email protected]>