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

const data in C result in unsupported BPF relocation R_BPF_INSN_64 #17989

Closed
jackcmay opened this issue Jun 15, 2021 · 2 comments · Fixed by solana-labs/rbpf#200
Closed

const data in C result in unsupported BPF relocation R_BPF_INSN_64 #17989

jackcmay opened this issue Jun 15, 2021 · 2 comments · Fixed by solana-labs/rbpf#200
Assignees

Comments

@jackcmay
Copy link
Contributor

Problem

Read-only data in C programs result in a R_BPF_INSN_64 relocation that the loader does not recognize.

Code that cause it:

const SolPubkey my_pubkey =  = {.x = {0x4E, 0x2F, 0x5C, 0x61, 0x0A, 0x8D, 0x0A, 0x7C, 0xA8, 0x7F, 0xAB, 0x69, 0xAB, 0x03, 0x7B, 0x0A, 0x52, 0x4C, 0x53, 0xE4, 0xA9, 0x97, 0xE8, 0x0E, 0xA8, 0x5A, 0x48, 0x8B, 0x96, 0xB8, 0xF1, 0x53}};

Warning from the loader:

Error: ELF error: ELF error: Relocation failed, unknown type 1

The workaround is to use #define instead of const:

#define my_pubkey {.x = {0x4E, 0x2F, 0x5C, 0x61, 0x0A, 0x8D, 0x0A, 0x7C, 0xA8, 0x7F, 0xAB, 0x69, 0xAB, 0x03, 0x7B, 0x0D, 0x52, 0x4C, 0x53, 0xE4, 0xA9, 0x97, 0xE8, 0x0E, 0xA8, 0x5A, 0x48, 0x8B, 0x96, 0xB8, 0xF1, 0x53}};

This issue might be related to recent llvm updates

Proposed Solution

Investigate whether we can support R_BPF_INSN_64 and add support for it if possible.

@dmakarov
Copy link
Contributor

dmakarov commented Jul 1, 2021

I tested the following program

#include <solana_sdk.h>

extern uint64_t entrypoint(const uint8_t *input) {
  const SolPubkey my_pubkey = { .x = {
      0x4E, 0x2F, 0x5C, 0x61,
      0x0A, 0x8D, 0x0A, 0x7C,
      0xA8, 0x7F, 0xAB, 0x69,
      0xAB, 0x03, 0x7B, 0x0A,
      0x52, 0x4C, 0x53, 0xE4,
      0xA9, 0x97, 0xE8, 0x0E,
      0xA8, 0x5A, 0x48, 0x8B,
      0x96, 0xB8, 0xF1, 0x53
    }};

  uint8_t pubkey[] = { \
        0x4E, 0x2F, 0x5C, 0x61, \
        0x0A, 0x8D, 0x0A, 0x7C, \
        0xA8, 0x7F, 0xAB, 0x69, \
        0xAB, 0x03, 0x7B, 0x0A, \
        0x52, 0x4C, 0x53, 0xE4, \
        0xA9, 0x97, 0xE8, 0x0E, \
        0xA8, 0x5A, 0x48, 0x8B, \
        0x96, 0xB8, 0xF1, 0x53  \
  };

  SolPubkey your_pubkey;

  sol_memcpy(&(your_pubkey.x), pubkey, sizeof(pubkey));

  sol_assert(SolPubkey_same(&my_pubkey, &your_pubkey));

  return SUCCESS;
}

It compiles and works without error. Can you give an example of a program that triggers the error ELF error: Relocation failed, unknown type 1?

@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2022

This issue has been automatically locked since there has not been any activity in past 7 days after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants