Skip to content

Commit

Permalink
Compile bpf_alignchecker by datapath loader
Browse files Browse the repository at this point in the history
Remove bpf_alignchecker compiling from init.sh, and
replace it with datapath loader to compile bpf_alignchecker
this is part of work for deprecating init.sh

Signed-off-by: Vincent Li <v.li@f5.com>
  • Loading branch information
vincentmli authored and aanm committed Sep 20, 2022
1 parent 3d001a8 commit 8210bbf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
4 changes: 0 additions & 4 deletions bpf/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,3 @@ fi
if [ "$HOST_DEV1" != "$HOST_DEV2" ]; then
bpf_unload $HOST_DEV2 "egress"
fi

# Compile dummy BPF file containing all shared struct definitions used by
# pkg/alignchecker to validate C and Go equivalent struct alignments
bpf_compile bpf_alignchecker.c bpf_alignchecker.o obj ""
2 changes: 1 addition & 1 deletion pkg/datapath/linux/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewDatapath(cfg DatapathConfiguration, ruleManager datapath.IptablesManager
IptablesManager: ruleManager,
nodeAddressing: NewNodeAddressing(),
config: cfg,
loader: loader.NewLoader(canDisableDwarfRelocations),
loader: loader.NewLoader(),
wgAgent: wgAgent,
lbmap: lbmap.New(),
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/datapath/linux/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ var (

isRecKernelVer = versioncheck.MustCompile(">=" + recKernelVer)
isRecClangVer = versioncheck.MustCompile(">=" + recClangVer)

// LLVM/clang version which supports `-mattr=dwarfris`
isDwarfrisClangVer = versioncheck.MustCompile(">=7.0.0")
canDisableDwarfRelocations bool
)

func getClangVersion(filePath string) (semver.Version, error) {
Expand Down Expand Up @@ -105,7 +101,6 @@ func CheckMinRequirements() {
"your kernel version to at least %s",
clangVersion, kernelVersion, recKernelVer)
}
canDisableDwarfRelocations = isDwarfrisClangVer(clangVersion)
log.Infof("clang (%s) and kernel (%s) versions: OK!", clangVersion, kernelVersion)
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/datapath/loader/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ func (l *Loader) Reinitialize(ctx context.Context, o datapath.BaseProgramOwner,
return err
}

if l.canDisableDwarfRelocations {
// Validate alignments of C and Go equivalent structs
if err := alignchecker.CheckStructAlignments(defaults.AlignCheckerName); err != nil {
log.WithError(err).Fatal("C and Go structs alignment check failed")
}
} else {
log.Warning("Cannot check matching of C and Go common struct alignments due to old LLVM/clang version")
// Compile alignchecker program
if err := Compile(ctx, "bpf_alignchecker.c", defaults.AlignCheckerName); err != nil {
log.WithError(err).Fatal("alignchecker compile failed")
}
// Validate alignments of C and Go equivalent structs
if err := alignchecker.CheckStructAlignments(defaults.AlignCheckerName); err != nil {
log.WithError(err).Fatal("C and Go structs alignment check failed")
}

if err := l.reinitializeIPSec(ctx); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/datapath/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ type Loader struct {

// templateCache is the cache of pre-compiled datapaths.
templateCache *objectCache

canDisableDwarfRelocations bool
}

// NewLoader returns a new loader.
func NewLoader(canDisableDwarfRelocations bool) *Loader {
return &Loader{
canDisableDwarfRelocations: canDisableDwarfRelocations,
}
func NewLoader() *Loader {
return &Loader{}
}

// Init initializes the datapath cache with base program hashes derived from
Expand Down

0 comments on commit 8210bbf

Please sign in to comment.