From b9d6cea5016835ca5521469631e55f5c489aa0e7 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Fri, 18 Mar 2022 17:36:52 +0800 Subject: [PATCH] cmd/link: set alignment of compressed section based on arch The ELF compression header(Chdr) has Addralign field that is set to the alignment of the uncompressed section which makes section able to have a different alignment than the decompressed section. However `file` and other tools require both Chdr.Addralign and Addralign to be equal. Ref https://sourceware.org/bugzilla/show_bug.cgi?id=23919 Related #42136 Fixes #51769 Change-Id: I3cf99dbd2359932576420a3c0d342c7e91b99227 Reviewed-on: https://go-review.googlesource.com/c/go/+/393916 Trust: mzh Reviewed-by: Alessandro Arzilli Reviewed-by: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Fangrui Song --- src/cmd/link/internal/ld/dwarf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 289ebcb595..2e209d0c6b 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -2234,7 +2234,7 @@ func dwarfcompress(ctxt *Link) { compressedSegName = ".zdebug_" + ldr.SymSect(s).Name[len(".debug_"):] } sect := addsection(ctxt.loader, ctxt.Arch, &Segdwarf, compressedSegName, 04) - sect.Align = 1 + sect.Align = int32(ctxt.Arch.Alignment) sect.Length = uint64(len(z.compressed)) sect.Compressed = true newSym := ldr.MakeSymbolBuilder(compressedSegName)