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

CONFIG_DEBUG_INFO_BTF does not work with llvm-objdump + llvm-objcopy #779

Closed
nathanchance opened this issue Nov 26, 2019 · 12 comments
Closed
Assignees
Labels
[BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 11 This bug was fixed in LLVM 11.0 [TOOL] llvm-objcopy The issue is relevant to LLVM objcopy [TOOL] llvm-objdump The issue is relevant to LLVM objdump

Comments

@nathanchance
Copy link
Member

I came across a patch on the netdev mailing list regarding GNU objcopy and I wanted to make sure that llvm-obcopy would not regress. As it turns out, llvm-objcopy does not work at all on either x86_64 or aarch64 (I have not tested anything else).

x86_64 failure (defconfig + CONFIG_DEBUG_INFO + CONFIG_DEBUG_INFO_BTF):

$ make -j$(nproc) -s CC=clang LD=ld.lld OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump O=out.x86_64 distclean defconfig vmlinux
...
llvm-objcopy: error: invalid output format: 'ELF64-x86-64'

AArch64 failure (defconfig + CONFIG_DEBUG_INFO_BTF):

$ make -j$(nproc) -s ARCH=arm64 CC=clang CROSS_COMPILE=aarch64-linux-gnu- LD=ld.lld NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump O=out.aarch64 distclean defconfig vmlinux
...
llvm-objcopy: error: invalid output format: 'ELF64-aarch64-little'

The relevant snippet of code from scripts/link-vmlinux.sh:

# generate .BTF typeinfo from DWARF debuginfo
# ${1} - vmlinux image
# ${2} - file to dump raw BTF data into
gen_btf()
{
	local pahole_ver
	local bin_arch

	if ! [ -x "$(command -v ${PAHOLE})" ]; then
		info "BTF" "${1}: pahole (${PAHOLE}) is not available"
		return 1
	fi

	pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/')
	if [ "${pahole_ver}" -lt "113" ]; then
		info "BTF" "${1}: pahole version $(${PAHOLE} --version) is too old, need at least v1.13"
		return 1
	fi

	info "BTF" ${2}
	vmlinux_link ${1}
	LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1}

	# dump .BTF section into raw binary file to link with final vmlinux
	bin_arch=$(LANG=C ${OBJDUMP} -f ${1} | grep architecture | \
		cut -d, -f1 | cut -d' ' -f2)
	bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
		awk '{print $4}')
	${OBJCOPY} --dump-section .BTF=.btf.vmlinux.bin ${1} 2>/dev/null
	${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \
		--rename-section .data=.BTF .btf.vmlinux.bin ${2}
}

They are using the output from ${OBJDUMP} to set the -O flag on ${OBJCOPY}. With the GNU tools, these appear to be mapped 1:1 but that does not appear to be the case for LLVM.

For x86_64: llvm-objdump's file format is ELF64-x86-64 but llvm-objcopy expects an -O value of elf64-x86-64.

For AArch64 : llvm-objdump's file format is ELF64-aarch64-little but llvm-objcopy expects an -O value of elf64-littleaarch64.

I am not sure how to reconcile this.

NOTE: To reproduce this, you will need pahole 1.13 or newer. I just did this:

git clone git://git.kernel.org/pub/scm/devel/pahole/pahole.git
mkdir pahole/build
cd pahole/build
cmake -D__LIB=lib ..
make -j$(nproc)

and just added that build folder to my PATH to avoid actually installing it.

@nathanchance nathanchance added [BUG] Untriaged Something isn't working [BUG] linux A bug that should be fixed in the mainline kernel. [TOOL] llvm-objcopy The issue is relevant to LLVM objcopy [TOOL] llvm-objdump The issue is relevant to LLVM objdump labels Nov 26, 2019
@tpimh
Copy link

tpimh commented Nov 27, 2019

Maybe this should be fixed on LLVM side? Probably the easiest way to fix it is to change llvm-objdump output to match the expected -O value for llvm-objcopy.

@nathanchance
Copy link
Member Author

cc @rupprecht, I thought I did that initially but I forgot.

@rupprecht
Copy link

https://reviews.llvm.org/D74433 is one possible solution. There are other ways that might make this work, so we'll see which one sticks.

@rupprecht
Copy link

Also @MaskRay fyi

@MaskRay
Copy link
Member

MaskRay commented Feb 11, 2020

I vote for updating all the llvm::object::ObjectFile::getFileFormatName() derivatives to use lower case.

Please make comments if you agree so: https://reviews.llvm.org/D74433

rupprecht added a commit to llvm/llvm-project that referenced this issue Feb 12, 2020
Summary:
GNU objdump prints the file format in lowercase, e.g. `elf64-x86-64`. llvm-objdump prints `ELF64-x86-64` right now, even though piping that into llvm-objcopy refuses that as a valid arch to use.

As an example of a problem this causes, see: ClangBuiltLinux/linux#779

Reviewers: MaskRay, jhenderson, alexshap

Reviewed By: MaskRay

Subscribers: tpimh, sbc100, grimar, jvesely, nhaehnle, kerbowa, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74433
@rupprecht
Copy link

Should be fixed as of 60a8a504f16dbbc5f2a6887ecb668ef4cb834949, lemme know if not.

@nathanchance
Copy link
Member Author

x86_64 is fixed (although running into a different issue that I will post here shortly).

AArch64 still fails because llvm-objdump outputs elf64-aarch64-little but llvm-objcopy expects elf64-littleaarch64.

@nickdesaulniers
Copy link
Member

@rupprecht thoughts on aarch64?

@rupprecht
Copy link

I agree they should be compatible. For ELF it was fortunately just a casing issue, but the aarch64 difference is annoying. The two choices are:

  • Modify llvm-objdump to print a GNU objdump compatible name
  • Change llvm-objcopy to allow either bfd or llvm style names

I'm not sure which one I'd prefer, because they each have their pros/cons -- on one hand, we don't need to inherit so much legacy bfd naming. On the other hand, we do want llvm-objdump to produce GNU objdump compatible output. Either way, though, we should have llvm-objdump and llvm-objcopy be on the same page.

@MaskRay
Copy link
Member

MaskRay commented Mar 12, 2020

Jordan asked me to finish this:/

https://reviews.llvm.org/D76046 will update ARM and AArch64 to match BFD names.

@nickdesaulniers nickdesaulniers added [PATCH] Submitted A patch has been submitted for review [BUG] llvm A bug that should be fixed in upstream LLVM and removed [BUG] Untriaged Something isn't working [BUG] linux A bug that should be fixed in the mainline kernel. labels Mar 12, 2020
MaskRay added a commit to llvm/llvm-project that referenced this issue Mar 16, 2020
…ames

Follow-up for D74433

What the function returns are almost standard BFD names, except that "ELF" is
in uppercase instead of lowercase.

This patch changes "ELF" to "elf" and changes ARM/AArch64 to use their BFD names.
MIPS and PPC64 have endianness differences as well, but this patch does not intend to address them.

Advantages:

* llvm-objdump: the "file format " line matches GNU objdump on ARM/AArch64 objects
* "file format " line can be extracted and fed into llvm-objcopy -O literally.
  (ClangBuiltLinux/linux#779 has such a use case)

Affected tools: llvm-readobj, llvm-objdump, llvm-dwarfdump, MCJIT (internal implementation detail, not exposed)

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D76046
@MaskRay
Copy link
Member

MaskRay commented Mar 16, 2020

https://reviews.llvm.org/D76046 made llvm-objdump's "file format" line match ARM/AArch64/RISCV and big-endian PPC32/PPC64.

@nathanchance
Copy link
Member Author

With the commit causing #871 reverted, BTF can be successfully generated for aarch64 with LLVM at llvm/llvm-project@0616e99.

@nathanchance nathanchance added [PATCH] Accepted A submitted patch has been accepted upstream and removed [PATCH] Submitted A patch has been submitted for review [PATCH] Accepted A submitted patch has been accepted upstream labels Mar 16, 2020
@nathanchance nathanchance added the [FIXED][LLVM] 11 This bug was fixed in LLVM 11.0 label Mar 16, 2020
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Apr 1, 2020
Summary:
GNU objdump prints the file format in lowercase, e.g. `elf64-x86-64`. llvm-objdump prints `ELF64-x86-64` right now, even though piping that into llvm-objcopy refuses that as a valid arch to use.

As an example of a problem this causes, see: ClangBuiltLinux/linux#779

Reviewers: MaskRay, jhenderson, alexshap

Reviewed By: MaskRay

Subscribers: tpimh, sbc100, grimar, jvesely, nhaehnle, kerbowa, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74433
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Apr 2, 2020
…ames

Follow-up for D74433

What the function returns are almost standard BFD names, except that "ELF" is
in uppercase instead of lowercase.

This patch changes "ELF" to "elf" and changes ARM/AArch64 to use their BFD names.
MIPS and PPC64 have endianness differences as well, but this patch does not intend to address them.

Advantages:

* llvm-objdump: the "file format " line matches GNU objdump on ARM/AArch64 objects
* "file format " line can be extracted and fed into llvm-objcopy -O literally.
  (ClangBuiltLinux/linux#779 has such a use case)

Affected tools: llvm-readobj, llvm-objdump, llvm-dwarfdump, MCJIT (internal implementation detail, not exposed)

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D76046
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Summary:
GNU objdump prints the file format in lowercase, e.g. `elf64-x86-64`. llvm-objdump prints `ELF64-x86-64` right now, even though piping that into llvm-objcopy refuses that as a valid arch to use.

As an example of a problem this causes, see: ClangBuiltLinux/linux#779

Reviewers: MaskRay, jhenderson, alexshap

Reviewed By: MaskRay

Subscribers: tpimh, sbc100, grimar, jvesely, nhaehnle, kerbowa, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74433
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
…ames

Follow-up for D74433

What the function returns are almost standard BFD names, except that "ELF" is
in uppercase instead of lowercase.

This patch changes "ELF" to "elf" and changes ARM/AArch64 to use their BFD names.
MIPS and PPC64 have endianness differences as well, but this patch does not intend to address them.

Advantages:

* llvm-objdump: the "file format " line matches GNU objdump on ARM/AArch64 objects
* "file format " line can be extracted and fed into llvm-objcopy -O literally.
  (ClangBuiltLinux/linux#779 has such a use case)

Affected tools: llvm-readobj, llvm-objdump, llvm-dwarfdump, MCJIT (internal implementation detail, not exposed)

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D76046
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 11 This bug was fixed in LLVM 11.0 [TOOL] llvm-objcopy The issue is relevant to LLVM objcopy [TOOL] llvm-objdump The issue is relevant to LLVM objdump
Projects
None yet
Development

No branches or pull requests

5 participants