Fix error: "failed to pin map: Bad file descriptor, path:
/sys/fs/bpf/_rodata_str1_1."
In the old kernel, the global data map will not be created, see [0]. So
we should skip the pinning of the global data map to avoid
bpf_object__pin_maps returning error. Therefore, when the map is not
created, we mark “map->skipped" as true and then check during relocation
and during pinning.
Fixes: 16e0c35c6f7a ("libbpf: Load global data maps lazily on legacy kernels")
Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
        char *pin_path;
        bool pinned;
        bool reused;
+       bool skipped;
        __u64 map_extra;
 };
 
                 * kernels.
                 */
                if (bpf_map__is_internal(map) &&
-                   !kernel_supports(obj, FEAT_GLOBAL_DATA))
+                   !kernel_supports(obj, FEAT_GLOBAL_DATA)) {
+                       map->skipped = true;
                        continue;
+               }
 
                retried = false;
 retry:
                        } else {
                                const struct bpf_map *map = &obj->maps[relo->map_idx];
 
-                               if (bpf_map__is_internal(map) &&
-                                   !kernel_supports(obj, FEAT_GLOBAL_DATA)) {
+                               if (map->skipped) {
                                        pr_warn("prog '%s': relo #%d: kernel doesn't support global data\n",
                                                prog->name, i);
                                        return -ENOTSUP;
                char *pin_path = NULL;
                char buf[PATH_MAX];
 
+               if (map->skipped)
+                       continue;
+
                if (path) {
                        int len;