Skip to content

[Bug](aarch64) Fix the mmap errors which make BE down during starting up#13031

Merged
yiguolei merged 1 commit intoapache:masterfrom
adonis0147:aarch64
Sep 29, 2022
Merged

[Bug](aarch64) Fix the mmap errors which make BE down during starting up#13031
yiguolei merged 1 commit intoapache:masterfrom
adonis0147:aarch64

Conversation

@adonis0147
Copy link
Contributor

Proposed changes

Issue Number: close #13026

Problem summary

I failed to start BE (with ASAN build type) up on Ubuntu 22.04.1 (aarch64) and got the following errors.

==46318==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of ReadFileToBuffer (error code: 22)
ERROR: Failed to mmap

Use strace to inspect the syscall

$ strace ./doris_be
...

mmap(NULL, 0, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 EINVAL (Invalid argument)
getpid()                                = 48376
write(2, "==48376==ERROR: AddressSanitizer"..., 103==48376==ERROR: AddressSanitizer failed to allocate 0x0 (0) bytes of ReadFileToBuffer (error code: 22)
) = 103
mmap(NULL, 0, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 EINVAL (Invalid argument)
write(2, "ERROR: Failed to mmap\n", 22ERROR: Failed to mmap
) = 22
exit_group(0)                           = ?
+++ exited with 0 +++

The signature of mmap

void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);

According to the result of strace, it was zero length which caused the Invalid argument errors.

The implementation of function ReadFileToBuffer in gcc-11-11.2.0/gcc-11.2.0/libsanitizer/sanitizer_common/sanitizer_file.cpp

bool ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size,
                      uptr *read_len, uptr max_len, error_t *errno_p) {
  *buff = nullptr;
  *buff_size = 0;
  *read_len = 0;
  if (!max_len)
    return true;
  uptr PageSize = GetPageSizeCached();
  uptr kMinFileLen = Min(PageSize, max_len);

  // The files we usually open are not seekable, so try different buffer sizes.
  for (uptr size = kMinFileLen;; size = Min(size * 2, max_len)) {
    UnmapOrDie(*buff, *buff_size);
    *buff = (char*)MmapOrDie(size, __func__);
    *buff_size = size;
    fd_t fd = OpenFile(file_name, RdOnly, errno_p);
    if (fd == kInvalidFd) {
      UnmapOrDie(*buff, *buff_size);
      return false;
    }
    *read_len = 0;
    // Read up to one page at a time.
    bool reached_eof = false;
    while (*read_len < size) {
      uptr just_read;
      if (!ReadFromFile(fd, *buff + *read_len, size - *read_len, &just_read,
                        errno_p)) {
        UnmapOrDie(*buff, *buff_size);
        CloseFile(fd);
        return false;
      }
      *read_len += just_read;
      if (just_read == 0 || *read_len == max_len) {
        reached_eof = true;
        break;
      }
    }
    CloseFile(fd);
    if (reached_eof)  // We've read the whole file.
      break;
  }
  return true;
}

It seems that GetPageSizeCached returned zero value and made the following mmap call fail.

After investigation, I figured out that be/src/glibc-compatibility/musl/getauxval.c masked the getauxval function and made this trouble.

Checklist(Required)

  1. Does it affect the original behavior:
    • Yes
    • No
    • I don't know
  2. Has unit tests been added:
    • Yes
    • No
    • No Need
  3. Has document been added or modified:
    • Yes
    • No
    • No Need
  4. Does it need to update dependencies:
    • Yes
    • No
  5. Are there any changes that cannot be rolled back:
    • Yes (If Yes, please explain WHY)
    • No

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

Copy link
Contributor

@BiteTheDDDDt BiteTheDDDDt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Sep 28, 2022
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@yiguolei yiguolei merged commit a853dd3 into apache:master Sep 29, 2022
@adonis0147 adonis0147 deleted the aarch64 branch September 29, 2022 02:34
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
FreeOnePlus pushed a commit to FreeOnePlus/doris that referenced this pull request Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug](aarch64) Failed to start BE due to errors caused by AddressSanitizer

3 participants