Skip to content

Commit

Permalink
Merge pull request #35 from parca-dev/add_glic_239
Browse files Browse the repository at this point in the history
Add glibc 2.39
  • Loading branch information
kakkoyun authored Feb 25, 2024
2 parents a576622 + 0b5a245 commit 981d002
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tmp
/debuginfofind
/apkdownload
/main
/keep
56 changes: 39 additions & 17 deletions cmd/debdownload/debdownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"archive/tar"
"bytes"
"context"
"errors"
"fmt"
Expand All @@ -19,6 +18,8 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/blakesmith/ar"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/zstd"
"github.com/peterbourgon/ff/v4"
"github.com/peterbourgon/ff/v4/ffhelp"
"github.com/ulikunitz/xz"
Expand Down Expand Up @@ -228,10 +229,6 @@ func (c *cli) list(ctx context.Context, pkgUrl, pkgName string, architectures []
}
}
variant := strings.TrimPrefix(matches[2], "-")
if c.sv == ubuntu && variant == "" {
// No need to download the main package for Ubuntu.
continue
}
if variant != "" {
if _, ok := allowedVariants[variant]; !ok {
continue
Expand Down Expand Up @@ -356,33 +353,54 @@ func (c *cli) extract(_ context.Context, packages []*pkg, outputDir string) erro
continue
}

r := ar.NewReader(f)
var extracted bool
ar := ar.NewReader(f)
for {
hdr, err := r.Next()
hdr, err := ar.Next()
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("failed to read next entry: %w", err)
}

if hdr.Name != "data.tar.xz" {
if !strings.HasPrefix(hdr.Name, "data.tar.") {
continue
}

c.logger.Info("extracting tar.xz", "file", hdr.Name)
c.logger.Info("extracting data.tar", "file", hdr.Name)

content, err := io.ReadAll(r)
if err != nil {
return fmt.Errorf("failed to read content: %w", err)
}
var r io.Reader
ext := filepath.Ext(hdr.Name)
switch ext {
case ".xz":
c.logger.Info("extracting tar.xz", "file", hdr.Name)

xzr, err := xz.NewReader(bytes.NewReader(content))
if err != nil {
return fmt.Errorf("failed to create xz reader: %w", err)
r, err = xz.NewReader(ar)
if err != nil {
return fmt.Errorf("failed to create xz reader: %w", err)
}
case ".zst":
c.logger.Info("extracting tar.zst", "file", hdr.Name)

r, err = zstd.NewReader(ar)
if err != nil {
return fmt.Errorf("failed to create zstd reader: %w", err)
}

case ".gz":
c.logger.Info("extracting tar.gz", "file", hdr.Name)

r, err = gzip.NewReader(ar)
if err != nil {
return fmt.Errorf("failed to create gzip reader: %w", err)
}

default:
return fmt.Errorf("unsupported extension: %s", ext)
}

tr := tar.NewReader(xzr)
tr := tar.NewReader(r)
for {
hdr, err := tr.Next()
if err == io.EOF {
Expand Down Expand Up @@ -412,8 +430,12 @@ func (c *cli) extract(_ context.Context, packages []*pkg, outputDir string) erro
if _, err := io.Copy(f, tr); err != nil {
return fmt.Errorf("failed to copy file: %w", err)
}
extracted = true
}
}
if !extracted {
return fmt.Errorf("failed to extract any files")
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/debuginfofind/debuginfofind.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

func main() {
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
Level: slog.LevelInfo,
}))

fSet := ff.NewFlagSet("debdownload")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
github.com/google/go-cmp v0.5.8
github.com/klauspost/compress v1.17.7
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4
github.com/ulikunitz/xz v0.5.11
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb h1:m935MPodAbYS46DG4
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAwrSvRx5DYA+gUcOIgTGVMNkfSCbZM8cWpI=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/peterbourgon/ff/v4 v4.0.0-alpha.4 h1:aiqS8aBlF9PsAKeMddMSfbwp3smONCn3UO8QfUg0Z7Y=
Expand Down
3 changes: 3 additions & 0 deletions scripts/download/glibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ for arch in $BIN_DIR/$PACKAGE_NAME/*; do
if [ ! -f "$target" ]; then
target="$variant"/lib/"$linuxArch"-linux-gnu/libc.so.6
fi
if [ ! -f "$target" ]; then
target="$variant"/usr/lib/"$linuxArch"-linux-gnu/libc.so.6
fi
dbginfo=$(./debuginfofind -d "$version"/dbg $target || true)
if [ -n "$dbginfo" ]; then
dbgTarget="$DEBUGINFO_DIR"/$PACKAGE_NAME/$a/$v/
Expand Down
2 changes: 1 addition & 1 deletion scripts/structlayout/glibc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ for arch in "${SOURCE_DIR}"/*; do
v=$(basename "${version}")
a=$(basename "${arch}")
echo "Running structlayout against glibc ${v} for ${a}..."
./structlayout -r glibc -v "${v}" -o "${TARGET_DIR}/${a}" "${dbgfile}"
./structlayout -r glibc -v "${v}" -o "${TARGET_DIR}/${a}" "${dbgfile}"
done
done
done

0 comments on commit 981d002

Please sign in to comment.