...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/time/asset_linux_amd64.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/time

     1  // Copyright 2022 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package time
    17  
    18  import (
    19  	"debug/elf"
    20  	"encoding/binary"
    21  )
    22  
    23  func AssetLD(rela elf.Rela64, imageOffset map[string]int, imageContent *[]byte, sym elf.Symbol, byteorder binary.ByteOrder) {
    24  	// The relocation of a X86 image is like:
    25  	// Relocation section '.rela.text' at offset 0x288 contains 3 entries:
    26  	// Offset          Info           Type           Sym. Value    Sym. Name + Addend
    27  	// 000000000016  000900000002 R_X86_64_PC32     0000000000000000 CLOCK_IDS_MASK - 4
    28  	// 00000000001f  000a00000002 R_X86_64_PC32     0000000000000008 TV_NSEC_DELTA - 4
    29  	// 00000000002a  000b00000002 R_X86_64_PC32     0000000000000010 TV_SEC_DELTA - 4
    30  	//
    31  	// For example, we need to write the offset of `CLOCK_IDS_MASK` - 4 in 0x16 of the section
    32  	// If we want to put the `CLOCK_IDS_MASK` at the end of the section, it will be
    33  	// len(imageContent) - 4 - 0x16
    34  
    35  	imageOffset[sym.Name] = len(*imageContent)
    36  	targetOffset := uint32(len(*imageContent)) - uint32(rela.Off) + uint32(rela.Addend)
    37  	byteorder.PutUint32((*imageContent)[rela.Off:rela.Off+4], targetOffset)
    38  
    39  	// TODO: support other length besides uint64 (which is 8 bytes)
    40  	*imageContent = append(*imageContent, make([]byte, varLength)...)
    41  }
    42