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

Add GCC 14 UBSAN container (Fedora 40) #81

Closed
wants to merge 7 commits into from

Conversation

pachadotdev
Copy link
Contributor

To address #80 and mimic one of the additional CRAN checks.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@gaborcsardi
Copy link
Collaborator

Thanks, we don't need a separate R build for this,if you set -fsanitize=undefined for any recent gcc version, it'll work.

@gaborcsardi
Copy link
Collaborator

 => ERROR [14/14] RUN echo -e 'CC = gcc-14 -std=gnu99 -fsanitize=address,undefined -fno-omit-frame-poin  0.5s
------
 > [14/14] RUN echo -e 'CC = gcc-14 -std=gnu99 -fsanitize=address,undefined -fno-omit-frame-pointer\nFC = gfortran-14 -fsanitize=address' >> ~/.R/Makevars:
0.451 /bin/sh: line 1: /root/.R/Makevars: No such file or directory

@gaborcsardi
Copy link
Collaborator

Can you please build this image and make sure that it works, i.e. it finds the error in your package, and also in some other packages with gcc-ubsan and gcc-asan errors on CRAN? Thanks!

@pachadotdev
Copy link
Contributor Author

Can you please build this image and make sure that it works, i.e. it finds the error in your package, and also in some other packages with gcc-ubsan and gcc-asan errors on CRAN? Thanks!

hi @gaborcsardi
I pushed what I had in local (i.e., "gcc" instead of "gcc-14")
Your current image does not support SAN, unless I install libubsan and modify the envvars.
This image does exactly that.

@gaborcsardi
Copy link
Collaborator

So can you try to make sure that this image reproduces the errors on CRAN?
https://www.stats.ox.ac.uk/pub/bdr/memtests/gcc-ASAN/iClusterVB/
https://www.stats.ox.ac.uk/pub/bdr/memtests/gcc-ASAN/quantreg/

Copy link
Collaborator

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

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

Thanks!

'install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/%s/%s/%s/%s", "devel", .Platform$pkgType, R.Version()$os, R.Version()$arch))'

# ------------------------------------------------------------------------------------
# Install pkgbuild, rcmdcheck, and decor
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed? It is also error prone, because install.packages() does not error on installation failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not really needed
the pak part was copied from the gcc14 dockerfile

# adapted from https://www.stats.ox.ac.uk/pub/bdr/memtests/README.txt

RUN mkdir -p ~/.R/ && echo -e 'CC=gcc -std=gnu11 -fsanitize=address,undefined -fno-omit-frame-pointer\nFC=gfortran -fsanitize=address' >> ~/.R/Makevars
ENV LD_PRELOAD=/usr/lib64/libasan.so.8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding this as a global env var is not great, because all programs are going to use it, and the whole system will be very slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that was to avoid warnings like "libasan not loaded 1st"

@pachadotdev
Copy link
Contributor Author

I modified my PR to use the existing image with minimal changes

This is how I can imitate the CRAN setup (https://www.stats.ox.ac.uk/pub/bdr/memtests/README.txt)

# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

name: R package

permissions: read-all

jobs:
  R-CMD-check:
    runs-on: ${{ matrix.config.os }}
    container: ${{ matrix.config.container }}

    name: ${{ matrix.config.name }}

    strategy:
      fail-fast: false
      matrix:
        config:
          - {os: ubuntu-latest, container: { image: 'ghcr.io/r-hub/containers/gcc13:latest' }, name: 'gcc14'}
          - {os: ubuntu-latest, container: { image: 'your-docker-image:latest' }, name: 'fedora-gcc14'}

    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
      R_KEEP_PKG_SOURCE: yes
      ASAN_OPTIONS: 'detect_leaks=0'
      UBSAN_OPTIONS: 'print_stacktrace=1'
      RJAVA_JVM_STACK_WORKAROUND: 0
      RGL_USE_NULL: true
      R_DONT_USE_TK: true
      LD_PRELOAD: /usr/lib64/libasan.so.8

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up R environment
        run: |
          mkdir -p ~/.R/
          echo 'CC=gcc -std=gnu11 -fsanitize=address,undefined -fno-omit-frame-pointer' >> ~/.R/Makevars
          echo 'FC=gfortran -fsanitize=address' >> ~/.R/Makevars

      - name: Restore R package cache
        uses: actions/cache@v4
        with:
          path: ~/.cache/R
          key: ${{ runner.os }}-r-${{ matrix.config.r }}-cache

      - name: Install dependencies
        run: |
          Rscript -e 'if (!requireNamespace("pak", quietly = TRUE)) { install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/") }'
          Rscript -e 'pak::pkg_install("decor", dependencies = TRUE)'
          Rscript -e 'pak::pkg_install("rcmdcheck", dependencies = TRUE)'
          Rscript -e 'pak::pkg_install("pkgbuild", dependencies = TRUE)'
          Rscript -e 'pak::pkg_install(".", dependencies = TRUE)'
        working-directory: ./rpkg
        
      - name: Check
        run: |
          Rscript -e 'pkgbuild::check_build_tools(debug = TRUE)'
          Rscript -e 'rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), build_args = "--no-manual", error_on = "error")'
        working-directory: ./rpkg

      - name: Save R package cache
        uses: actions/cache@v4
        with:
          path: ~/.cache/R
          key: ${{ runner.os }}-r-${{ matrix.config.r }}-cache

@krlmlr
Copy link
Contributor

krlmlr commented Feb 24, 2025

What do we need for this to fly? I'm seeing ubsan failures for RSQLite. Thanks!

@gaborcsardi
Copy link
Collaborator

What do we need for this to fly? I'm seeing ubsan failures for RSQLite. Thanks!

Try the clang-ubsan container, in my experience it tends to finds all gcc-ubsan issues and more.

@krlmlr
Copy link
Contributor

krlmlr commented Feb 24, 2025

@andrjohns
Copy link

+1 that a gcc-ubsan image would be great! I also just had a case of getting gcc-UBSAN errors on CRAN but not from the R-Hub clang-ubsan or clang-asan:

CRAN: https://www.stats.ox.ac.uk/pub/bdr/memtests/gcc-UBSAN/QuickJSR/QuickJSR-Ex.Rout
GHA: https://github.com/andrjohns/QuickJSR/actions/runs/13545259248/job/37855189870

@gaborcsardi
Copy link
Collaborator

@krlmlr @andrjohns Try this container: https://github.com/r-hub/containers/pkgs/container/containers%2Fgcc-asan

You'll need to reset options("repos") and use install.packages() if pak crashes during the installation of the dependencies.

@andrjohns
Copy link

@krlmlr @andrjohns Try this container: https://github.com/r-hub/containers/pkgs/container/containers%2Fgcc-asan

You'll need to reset options("repos") and use install.packages() if pak crashes during the installation of the dependencies.

Thanks! I think the container needs to set ENV LD_PRELOAD="/usr/lib/gcc/x86_64-redhat-linux/14/libasan.so": https://github.com/andrjohns/QuickJSR/actions/runs/13547608628/job/37863017481

@gaborcsardi
Copy link
Collaborator

gaborcsardi commented Feb 26, 2025

That's not so good because then it is set for every process, not just R. I already set it in the R startup script, but it seems like I also need to set it for Rscript, or use R to start the check instead of Rscript. (Which you can also do if you run the container interactively.)

OTOH, Rscript calls R CMD check, so it should still work, I think. I'll try to debug this more...

@gaborcsardi
Copy link
Collaborator

@andrjohns I made a new release that works for me. Please open an issue if you run into problems.

Since there is a gcc-asan containers now (which also works for UBSAN), I am going to close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants