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

cmd/link: migrate from legacy .zdebug to SHF_COMPRESSED for ELF #50796

Closed
MaskRay opened this issue Jan 25, 2022 · 7 comments
Closed

cmd/link: migrate from legacy .zdebug to SHF_COMPRESSED for ELF #50796

MaskRay opened this issue Jan 25, 2022 · 7 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@MaskRay
Copy link

MaskRay commented Jan 25, 2022

#11799 uses the legacy ELF compression format .zdebug_* instead of the standard SHF_COMPRESSED defined by the generic ABI. I understand that there is cross-binary-format convenience (Mach-O doesn't have SHF_COMPRESSED), but it'd be nice if Go matches the prevailing style and switches to SHF_COMPRESSED for ELF. In 2015-07, the binutils patch [PATCH] Make default compression gABI compliant (milestone: binutils 2.26) switched the default to the generic ABI format. It has been very difficult to find new .zdebug from that time on. New tools developed for ELF than would not be to support Go created legacy .zdebug* sections. We don't have to worry about the toolchain compatibility. There are more tools understanding SHF_COMPRESSES than tools only understanding .zdebug.

http://www.linker-aliens.org/blogs/ali/entry/elf_section_compression/ has some notes about alignment issues with .zdebug.

For Mach-O, since there isn't a section attribute, we may stick with __zdebug_.

@mengzhuo
Copy link
Contributor

mengzhuo commented Jan 25, 2022

Is it sect.Flags |= SHF_COMPRESSED in this compressed section helps?

} else {
compressedSegName := ".zdebug_" + ldr.SymSect(s).Name[len(".debug_"):]
sect := addsection(ctxt.loader, ctxt.Arch, &Segdwarf, compressedSegName, 04)
sect.Align = 1
sect.Length = uint64(len(z.compressed))
newSym := ldr.CreateSymForUpdate(compressedSegName, 0)
newSym.SetData(z.compressed)
newSym.SetSize(int64(len(z.compressed)))
ldr.SetSymSect(newSym.Sym(), sect)
ds := dwarfSecInfo{syms: []loader.Sym{newSym.Sym()}}
newDwarfp = append(newDwarfp, ds)

@MaskRay
Copy link
Author

MaskRay commented Jan 25, 2022

There is a header difference beside sect.Flags |= SHF_COMPRESSED.

The legacy .zdebug format uses (per http://www.linker-aliens.org/blogs/ali/entry/elf_section_compression/):

typedef struct {
	uchar_t		gch_magic[4];  /* [ 'Z', 'L', 'I', 'B'] */
	uchar_t		gch_size[8];   /* unaligned 64-bit ELFDATAMSB integer */
} Chdr_GNU;

The generic ABI standard format (SHF_COMPRESSED) uses:
http://www.sco.com/developers/gabi/latest/ch4.sheader.html

typedef struct {
	Elf32_Word	ch_type;
	Elf32_Word	ch_size;
	Elf32_Word	ch_addralign;
} Elf32_Chdr;

typedef struct {
	Elf64_Word	ch_type;
	Elf64_Word	ch_reserved;
	Elf64_Xword	ch_size;
	Elf64_Xword	ch_addralign;
} Elf64_Chdr;

@mknyszek mknyszek added this to the Backlog milestone Jan 25, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 25, 2022
@mknyszek
Copy link
Contributor

mknyszek commented Jan 25, 2022

CC @thanm @cherrymui @aclements

@cherrymui
Copy link
Member

cherrymui commented Jan 25, 2022

cc @aclements @thanm

Maybe the old format was used because of old versions of GDB? @aclements might remember.

@aarzilli
Copy link
Contributor

aarzilli commented Jan 25, 2022

Maybe the old format was used because of old versions of GDB? @aclements might remember.

I think the reason is that there is no equivalent of compressed sections in mach-o and PE, which would have to either be uncompressed or use zdebug anyway.

@gopherbot
Copy link

gopherbot commented Jan 26, 2022

Change https://golang.org/cl/380755 mentions this issue: cmd/link: enable compress header for ELF

@gopherbot
Copy link

gopherbot commented Jun 7, 2022

Change https://go.dev/cl/410823 mentions this issue: doc/go1.19: document linker CL that switches DWARF compressed section format

gopherbot pushed a commit that referenced this issue Jun 7, 2022
… format

For #51400.
Updates #50796.

Change-Id: Ica6c700a5b54e4712b09c43d1d7a9c3bba408b8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/410823
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Fangrui Song <maskray@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants