Address-sanitizer not working, workaround

Please point me to a place to issue a ticket about this. I'll write down my steps here in case more people run into the same problem.

I use opewrt 21.02.3, but this applies for older versions as well.
To get address-sanitizer, first I need to select GLIBC in the advanced settings, and libasan in base files. I also have to edit the file toolchain/gcc/final/Makefile. Like this:

sed -i "s/--disable-libsanitizer/--enable-libsanitizer/g" toolchain/gcc/final/Makefile
sed -i "s/+\$(GCC_MAKE) \$(HOST_JOBS) -C \$(GCC_BUILD_DIR) install/+\$(GCC_MAKE) \$(HOST_JOBS) -C \$(GCC_BUILD_DIR) install-target-libsanitizer/g" toolchain/gcc/final/Makefile

Now after buildling tools and toolchain, I can link and run my programs with asan.

I followed this document as reference:
https://blog.fem.tu-ilmenau.de/archives/994-HowTo-enable-address-sanitizer-with-OpenWRT.html

Here is my dockerfile if someones interested. This is for Netgear R7800 (Nighthawk X4S):

# you must build the openwrt_builder image first: https://github.com/mwarning/docker-openwrt-builder
FROM openwrt_builder

USER user

# https://openwrt.org/docs/guide-developer/toolchain/use-buildsystem
RUN cd /home/user &&\
    git clone https://github.com/openwrt/openwrt.git &&\
    cd openwrt &&\
    git pull &&\
    git branch -a &&\
    git tag &&\
    git checkout v21.02.3 &&\
    ./scripts/feeds update -a &&\
    ./scripts/feeds install -a

WORKDIR /home/user/openwrt

COPY --chown=user:user diffconfig .config
RUN make defconfig

# enable libsanitizer in GCC (asuming that you are using glibc, see the diffconfig)
RUN sed -i "s/--disable-libsanitizer/--enable-libsanitizer/g" toolchain/gcc/final/Makefile &&\
    sed -i "s/+\$(GCC_MAKE) \$(HOST_JOBS) -C \$(GCC_BUILD_DIR) install/+\$(GCC_MAKE) \$(HOST_JOBS) -C \$(GCC_BUILD_DIR) install-target-libsanitizer/g" toolchain/gcc/final/Makefile

RUN make tools/install -j4 &&\
    make toolchain/install -j4

WORKDIR /home/user

The diffconfig file used:

CONFIG_TARGET_ipq806x=y
CONFIG_TARGET_ipq806x_generic=y
CONFIG_TARGET_ipq806x_generic_DEVICE_netgear_r7800=y
CONFIG_DEVEL=y
CONFIG_TOOLCHAINOPTS=y
CONFIG_LIBC="glibc"
CONFIG_LIBC_USE_GLIBC=y
# CONFIG_LIBC_USE_MUSL is not set
CONFIG_PACKAGE_libasan=y
CONFIG_PACKAGE_librt=y
CONFIG_PACKAGE_libstdcpp=y
CONFIG_STRIP_ARGS="--strip-all"
CONFIG_TARGET_SUFFIX="gnueabi"
CONFIG_USE_GLIBC=y
CONFIG_USE_LIBSTDCXX=y
CONFIG_USE_STRIP=y
# CONFIG_USE_UCLIBCXX is not set

(you might consider also CONFIG_DEBUG=y and CONFIG_NO_STRIP=y)

If anyone is following along, if you change gcc version to 10.x, and add address-sanitizer as described above, the gcc build will fail.

How about using static-libasan to debug ?

I didin't modify gcc/final/Makefile and CONFIG_PACKAGE_libasan is not set.

add -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -g -static-libasan at target Makefile
ex.

all: $(OBJS)
	$(CC) -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -g -static-libasan  $(OBJS) -o $(TARGET1) $(CFLAGS) $(LDFLAGS)

%.o: %.c
	$(CC) -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -g -static-libasan $(CFLAGS) -c $<

My environment version:
OpenWrt 21.02.1, OpenWrt GCC 8.4.0